Skip to content

Conversation

klausler
Copy link
Contributor

Code to attach a procedure's declaration to an error message did not allow for ENTRY names, which can be in the global scope.

Fixes #158405.

Code to attach a procedure's declaration to an error message did
not allow for ENTRY names, which can be in the global scope.

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

llvmbot commented Sep 15, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Code to attach a procedure's declaration to an error message did not allow for ENTRY names, which can be in the global scope.

Fixes #158405.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+9-5)
  • (added) flang/test/Semantics/bug158405.f90 (+9)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 84edcebc64973..1049a6d2c1b2e 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -4164,13 +4164,17 @@ void DistinguishabilityHelper::SayNotDistinguishable(const Scope &scope,
 // comes from a different module but is not necessarily use-associated.
 void DistinguishabilityHelper::AttachDeclaration(
     parser::Message &msg, const Scope &scope, const Symbol &proc) {
-  const Scope &unit{GetTopLevelUnitContaining(proc)};
-  if (unit == scope) {
+  if (proc.owner().IsTopLevel()) {
     evaluate::AttachDeclaration(msg, proc);
   } else {
-    msg.Attach(unit.GetName().value(),
-        "'%s' is USE-associated from module '%s'"_en_US, proc.name(),
-        unit.GetName().value());
+    const Scope &unit{GetTopLevelUnitContaining(proc)};
+    if (unit == scope) {
+      evaluate::AttachDeclaration(msg, proc);
+    } else {
+      msg.Attach(unit.GetName().value(),
+          "'%s' is USE-associated from module '%s'"_en_US, proc.name(),
+          unit.GetName().value());
+    }
   }
 }
 
diff --git a/flang/test/Semantics/bug158405.f90 b/flang/test/Semantics/bug158405.f90
new file mode 100644
index 0000000000000..3c334675dfd64
--- /dev/null
+++ b/flang/test/Semantics/bug158405.f90
@@ -0,0 +1,9 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+subroutine s()
+  ! ERROR: Generic 'f' may not have specific procedures 's' and 'ss' as their interfaces are not distinguishable
+  interface f
+    procedure s
+    procedure ss
+  end interface
+ entry ss()
+end

@klausler klausler merged commit 2b0f25d into llvm:main Sep 17, 2025
12 checks passed
@klausler klausler deleted the bug158405 branch September 17, 2025 16:15
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] fatal internal error: CHECK(!start.IsTopLevel()) failed at /root/llvm-project/flang/lib/Semantics/tools.cpp(41)

3 participants