Skip to content

Commit

Permalink
[flang] Catch attempt to type a subroutine (llvm#82704)
Browse files Browse the repository at this point in the history
The presence of a type in the prefix of a SUBROUTINE statement should
elicit an error message, not a crash.

Fixes llvm#80530.
  • Loading branch information
klausler authored Mar 1, 2024
1 parent 8f80d46 commit a56ef9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3711,13 +3711,17 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) {
// Save this to process after UseStmt and ImplicitPart
if (const auto *parsedType{std::get_if<parser::DeclarationTypeSpec>(&x.u)}) {
FuncResultStack::FuncInfo &info{DEREF(funcResultStack().Top())};
if (info.parsedType) { // C1543
Say(currStmtSource().value(),
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
if (FuncResultStack::FuncInfo * info{funcResultStack().Top()}) {
if (info->parsedType) { // C1543
Say(currStmtSource().value(),
"FUNCTION prefix cannot specify the type more than once"_err_en_US);
} else {
info->parsedType = parsedType;
info->source = currStmtSource();
}
} else {
info.parsedType = parsedType;
info.source = currStmtSource();
Say(currStmtSource().value(),
"SUBROUTINE prefix cannot specify a type"_err_en_US);
}
return false;
} else {
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/typed-subr.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! ERROR: SUBROUTINE prefix cannot specify a type
integer subroutine foo
end

0 comments on commit a56ef9f

Please sign in to comment.