Skip to content

Commit 3ac0078

Browse files
authored
[flang] Fix crash on erroneous program (#123843)
Catch and report multiple initializations of the same procedure pointer rather than assuming that control wouldn't reach a given point in name resolution in that case. Fixes #123538.
1 parent b16c989 commit 3ac0078

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8630,8 +8630,11 @@ void DeclarationVisitor::PointerInitialization(
86308630
if (!context().HasError(ultimate)) {
86318631
if (IsProcedurePointer(ultimate)) {
86328632
auto &details{ultimate.get<ProcEntityDetails>()};
8633-
CHECK(!details.init());
8634-
if (const auto *targetName{std::get_if<parser::Name>(&target.u)}) {
8633+
if (details.init()) {
8634+
Say(name, "'%s' was previously initialized"_err_en_US);
8635+
context().SetError(ultimate);
8636+
} else if (const auto *targetName{
8637+
std::get_if<parser::Name>(&target.u)}) {
86358638
Walk(target);
86368639
if (!CheckUseError(*targetName) && targetName->symbol) {
86378640
// Validation is done in declaration checking.
@@ -8642,8 +8645,7 @@ void DeclarationVisitor::PointerInitialization(
86428645
}
86438646
} else {
86448647
Say(name,
8645-
"'%s' is not a procedure pointer but is initialized "
8646-
"like one"_err_en_US);
8648+
"'%s' is not a procedure pointer but is initialized like one"_err_en_US);
86478649
context().SetError(ultimate);
86488650
}
86498651
}

flang/test/Semantics/bug123538.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!RUN: %python %S/test_errors.py %s %flang_fc1
2+
procedure(), pointer :: pp => tan
3+
!ERROR: EXTERNAL attribute was already specified on 'pp'
4+
!ERROR: POINTER attribute was already specified on 'pp'
5+
!ERROR: 'pp' was previously initialized
6+
procedure(real), pointer :: pp => tan
7+
end

0 commit comments

Comments
 (0)