Skip to content

Commit dda9caf

Browse files
committed
[flang] Fix crash in error recovery
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.
1 parent 8ae3aea commit dda9caf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,13 +4164,17 @@ void DistinguishabilityHelper::SayNotDistinguishable(const Scope &scope,
41644164
// comes from a different module but is not necessarily use-associated.
41654165
void DistinguishabilityHelper::AttachDeclaration(
41664166
parser::Message &msg, const Scope &scope, const Symbol &proc) {
4167-
const Scope &unit{GetTopLevelUnitContaining(proc)};
4168-
if (unit == scope) {
4167+
if (proc.owner().IsTopLevel()) {
41694168
evaluate::AttachDeclaration(msg, proc);
41704169
} else {
4171-
msg.Attach(unit.GetName().value(),
4172-
"'%s' is USE-associated from module '%s'"_en_US, proc.name(),
4173-
unit.GetName().value());
4170+
const Scope &unit{GetTopLevelUnitContaining(proc)};
4171+
if (unit == scope) {
4172+
evaluate::AttachDeclaration(msg, proc);
4173+
} else {
4174+
msg.Attach(unit.GetName().value(),
4175+
"'%s' is USE-associated from module '%s'"_en_US, proc.name(),
4176+
unit.GetName().value());
4177+
}
41744178
}
41754179
}
41764180

flang/test/Semantics/bug158405.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
subroutine s()
3+
! ERROR: Generic 'f' may not have specific procedures 's' and 'ss' as their interfaces are not distinguishable
4+
interface f
5+
procedure s
6+
procedure ss
7+
end interface
8+
entry ss()
9+
end

0 commit comments

Comments
 (0)