Skip to content

Conversation

valerydmit
Copy link
Contributor

When generic interface name shadows specific, bypass to specific procedure while resolving its type.

When generic interface name shadows specific, bypass
to specific procedure while resolving its type.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2025

@llvm/pr-subscribers-flang-semantics

Author: Valery Dmitriev (valerydmit)

Changes

When generic interface name shadows specific, bypass to specific procedure while resolving its type.


Full diff: https://github.com/llvm/llvm-project/pull/162205.diff

3 Files Affected:

  • (modified) flang/include/flang/Semantics/symbol.h (+3)
  • (added) flang/test/Semantics/Inputs/generic-shadows-specific-a.f90 (+21)
  • (added) flang/test/Semantics/generic-shadows-specific-b.f90 (+13)
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/Semantics/Inputs/generic-shadows-specific-a.f90 b/flang/test/Semantics/Inputs/generic-shadows-specific-a.f90
new file mode 100644
index 0000000000000..bf3c6d464c7dd
--- /dev/null
+++ b/flang/test/Semantics/Inputs/generic-shadows-specific-a.f90
@@ -0,0 +1,21 @@
+! these modules must be read from  module files
+module 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 m2
+   use m1
+end
+module m3
+   use m2 ! must be m2, not m1
+ contains
+   subroutine mustExist() ! not called, but must exist
+     character x
+     x = f()
+   end
+end
diff --git a/flang/test/Semantics/generic-shadows-specific-b.f90 b/flang/test/Semantics/generic-shadows-specific-b.f90
new file mode 100644
index 0000000000000..d1dcefc7499a0
--- /dev/null
+++ b/flang/test/Semantics/generic-shadows-specific-b.f90
@@ -0,0 +1,13 @@
+! Check that expected code produced with no crash.
+subroutine reproducer()
+  use m2
+  use m3
+  character x
+  x = f()
+end
+
+! RUN: %flang_fc1 -fsyntax-only %S/Inputs/generic-shadows-specific-a.f90
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+! CHECK-LABEL: func.func @_QPreproducer
+! CHECK: fir.call @_QMm1Pf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants