Skip to content

Commit a56ef9f

Browse files
authored
[flang] Catch attempt to type a subroutine (#82704)
The presence of a type in the prefix of a SUBROUTINE statement should elicit an error message, not a crash. Fixes #80530.
1 parent 8f80d46 commit a56ef9f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,13 +3711,17 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
37113711
bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) {
37123712
// Save this to process after UseStmt and ImplicitPart
37133713
if (const auto *parsedType{std::get_if<parser::DeclarationTypeSpec>(&x.u)}) {
3714-
FuncResultStack::FuncInfo &info{DEREF(funcResultStack().Top())};
3715-
if (info.parsedType) { // C1543
3716-
Say(currStmtSource().value(),
3717-
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
3714+
if (FuncResultStack::FuncInfo * info{funcResultStack().Top()}) {
3715+
if (info->parsedType) { // C1543
3716+
Say(currStmtSource().value(),
3717+
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
3718+
} else {
3719+
info->parsedType = parsedType;
3720+
info->source = currStmtSource();
3721+
}
37183722
} else {
3719-
info.parsedType = parsedType;
3720-
info.source = currStmtSource();
3723+
Say(currStmtSource().value(),
3724+
"SUBROUTINE prefix cannot specify a type"_err_en_US);
37213725
}
37223726
return false;
37233727
} else {

flang/test/Semantics/typed-subr.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
! ERROR: SUBROUTINE prefix cannot specify a type
3+
integer subroutine foo
4+
end

0 commit comments

Comments
 (0)