[flang-commits] [flang] 2b0f25d - [flang] Fix crash in error recovery (#158750)

via flang-commits flang-commits at lists.llvm.org
Wed Sep 17 09:15:38 PDT 2025


Author: Peter Klausler
Date: 2025-09-17T09:15:34-07:00
New Revision: 2b0f25d9c3fbabce9e53f349ee6775157755e91d

URL: https://github.com/llvm/llvm-project/commit/2b0f25d9c3fbabce9e53f349ee6775157755e91d
DIFF: https://github.com/llvm/llvm-project/commit/2b0f25d9c3fbabce9e53f349ee6775157755e91d.diff

LOG: [flang] Fix crash in error recovery (#158750)

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 https://github.com/llvm/llvm-project/issues/158405.

Added: 
    flang/test/Semantics/bug158405.f90

Modified: 
    flang/lib/Semantics/check-declarations.cpp

Removed: 
    


################################################################################
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 
diff erent 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


        


More information about the flang-commits mailing list