[flang-commits] [flang] a4015d9 - [flang] Fix crash resolving interface procedure type. (#162205)
    via flang-commits 
    flang-commits at lists.llvm.org
       
    Thu Oct  9 12:15:00 PDT 2025
    
    
  
Author: Valery Dmitriev
Date: 2025-10-09T12:14:55-07:00
New Revision: a4015d98d2ad3faba12d8c1a82942330852b9efd
URL: https://github.com/llvm/llvm-project/commit/a4015d98d2ad3faba12d8c1a82942330852b9efd
DIFF: https://github.com/llvm/llvm-project/commit/a4015d98d2ad3faba12d8c1a82942330852b9efd.diff
LOG: [flang] Fix crash resolving interface procedure type. (#162205)
When generic interface name shadows specific, bypass to specific
procedure while resolving its type.
Added: 
    flang/test/Lower/generic-shadows-specific.F90
Modified: 
    flang/include/flang/Semantics/symbol.h
Removed: 
    
################################################################################
diff  --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 975423b32da73..98e2a5fe88da4 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -1126,6 +1126,9 @@ inline const DeclTypeSpec *Symbol::GetTypeImpl(int depth) const {
           [&](const HostAssocDetails &x) {
             return x.symbol().GetTypeImpl(depth);
           },
+          [&](const GenericDetails &x) {
+            return x.specific() ? x.specific()->GetTypeImpl(depth) : nullptr;
+          },
           [](const auto &) -> const DeclTypeSpec * { return nullptr; },
       },
       details_);
diff  --git a/flang/test/Lower/generic-shadows-specific.F90 b/flang/test/Lower/generic-shadows-specific.F90
new file mode 100644
index 0000000000000..e72190884db13
--- /dev/null
+++ b/flang/test/Lower/generic-shadows-specific.F90
@@ -0,0 +1,40 @@
+
+#if STEP == 1
+! these modules must be read from  module files
+module generic_shadows_specific_m1
+  interface f ! reference must be to generic
+    module procedure f ! must have same name as generic interface
+  end interface
+ contains
+  character function f() ! must be character
+    f = 'q'
+  end
+end
+module generic_shadows_specific_m2
+   use generic_shadows_specific_m1
+end
+module generic_shadows_specific_m3
+   use generic_shadows_specific_m2 ! must be generic_shadows_specific_m2, not generic_shadows_specific_m1
+ contains
+   subroutine mustExist() ! not called, but must exist
+     character x
+     x = f()
+   end
+end
+
+#else
+! Check that expected code produced with no crash.
+subroutine reproducer()
+  use generic_shadows_specific_m2
+  use generic_shadows_specific_m3
+  character x
+  x = f()
+end
+#endif
+
+!RUN: rm -rf %t && mkdir -p %t
+!RUN: %flang_fc1 -fsyntax-only -DSTEP=1 -J%t %s
+!RUN: %flang_fc1 -emit-fir -J%t -o - %s | FileCheck %s
+
+!CHECK-LABEL: func.func @_QPreproducer
+!CHECK: fir.call @_QMgeneric_shadows_specific_m1Pf
        
    
    
More information about the flang-commits
mailing list