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-fir-hlfir

@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

jeanPerier
jeanPerier previously approved these changes Oct 7, 2025
Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit on the test. The fix makes sense to me, but please wait for @klausler before merging.

! Check that expected code produced with no crash.
subroutine reproducer()
use m2
use m3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failure you are seeing in the windows bot most likely comes from module file clashes.
LIT tests are run in parallel in the same folder.

Any tests that relies on writing and then reading a module file should be run in a temporary directory to avoid any troubles (m, m1, m2... are quite common name. It is OK when the test is a single compilation unit, but when doing several steps, the related module file will very likely be overridden).

You can use:

! RUN: rm -rf %t && mkdir -p %t

Also, as a nit, I think tests using -emit-fir/hlfir should live in test/Lower (there are a few precedent, but I do not think it is best practice). You can move it in test/Lower (there is no Input directory there, but you can achieve the same by making it single file test by using macros around the different steps of the compilation (see ./Semantics/modfile71.F90 for an example).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to allow tests with module files to run in parallel is to include the name of the test in the names of the modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for suggestions. I updated the test and moved to "Lower" subdir.

@jeanPerier jeanPerier dismissed their stale review October 7, 2025 14:05

Need test update.

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

Successfully merging this pull request may close these issues.

4 participants