Skip to content

Conversation

@klausler
Copy link
Contributor

A procedure defined in non-generic INTERFACE block must completely shadow any generic interface of the same name in an outer scope.

Fixes #164303.

A procedure defined in non-generic INTERFACE block must completely
shadow any generic interface of the same name in an outer scope.

Fixes llvm#164303.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

A procedure defined in non-generic INTERFACE block must completely shadow any generic interface of the same name in an outer scope.

Fixes #164303.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+5-1)
  • (added) flang/test/Semantics/bug164303.f90 (+31)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 0af1c94502bb4..d1160cc25a08b 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5433,7 +5433,8 @@ void SubprogramVisitor::PushBlockDataScope(const parser::Name &name) {
   }
 }
 
-// If name is a generic, return specific subprogram with the same name.
+// If name is a generic in the same scope, return its specific subprogram with
+// the same name, if any.
 Symbol *SubprogramVisitor::GetSpecificFromGeneric(const parser::Name &name) {
   // Search for the name but don't resolve it
   if (auto *symbol{currScope().FindSymbol(name.source)}) {
@@ -5443,6 +5444,9 @@ Symbol *SubprogramVisitor::GetSpecificFromGeneric(const parser::Name &name) {
         // symbol doesn't inherit it and ruin the ability to check it.
         symbol->attrs().reset(Attr::MODULE);
       }
+    } else if (&symbol->owner() != &currScope() && inInterfaceBlock() &&
+        !isGeneric()) {
+      // non-generic interface shadows outer definition
     } else if (auto *details{symbol->detailsIf<GenericDetails>()}) {
       // found generic, want specific procedure
       auto *specific{details->specific()};
diff --git a/flang/test/Semantics/bug164303.f90 b/flang/test/Semantics/bug164303.f90
new file mode 100644
index 0000000000000..c356c07392577
--- /dev/null
+++ b/flang/test/Semantics/bug164303.f90
@@ -0,0 +1,31 @@
+!RUN: %flang -fc1 -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+module foo_mod
+  use, intrinsic :: iso_fortran_env
+  use, intrinsic :: iso_c_binding
+  implicit none
+
+  interface new_foo
+    procedure :: foo_ctor
+  end interface
+
+contains
+
+function foo_ctor(options) result(retval)
+  implicit none
+  integer, intent(in) :: options
+  integer :: retval
+
+  interface
+!CHECK-NOT: error:
+    subroutine new_foo(f, opt) bind(c, name='new_foo')
+      import
+      implicit none
+      integer, intent(inout) :: f
+      integer(c_int), intent(in) :: opt
+    end subroutine
+  end interface
+
+  call new_foo(retval, options)
+end function
+
+end module

Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix.

@klausler klausler merged commit ef9494b into llvm:main Oct 21, 2025
12 of 13 checks passed
@klausler klausler deleted the bug164303 branch October 21, 2025 20:38
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
A procedure defined in non-generic INTERFACE block must completely
shadow any generic interface of the same name in an outer scope.

Fixes llvm#164303.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
A procedure defined in non-generic INTERFACE block must completely
shadow any generic interface of the same name in an outer scope.

Fixes llvm#164303.
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.

Flang does not look for locally scoped interfaces before module level interfaces with the same name

4 participants