diff options
author | Peter Klausler <35819229+klausler@users.noreply.github.com> | 2024-03-01 15:23:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-01 15:23:24 -0800 |
commit | a56ef9f9ced6c279e00671f4f8270e717517de46 (patch) | |
tree | d2e68512134aa2b8b6bb4f1d3c6dafc9f749fff3 | |
parent | 8f80d466d580d0fb97383eac8a2d7d9a1e3f15f4 (diff) | |
download | llvm-a56ef9f9ced6c279e00671f4f8270e717517de46.zip llvm-a56ef9f9ced6c279e00671f4f8270e717517de46.tar.gz llvm-a56ef9f9ced6c279e00671f4f8270e717517de46.tar.bz2 |
[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 https://github.com/llvm/llvm-project/issues/80530.
-rw-r--r-- | flang/lib/Semantics/resolve-names.cpp | 16 | ||||
-rw-r--r-- | flang/test/Semantics/typed-subr.f90 | 4 |
2 files changed, 14 insertions, 6 deletions
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index eb61a76..87b6130 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -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 { diff --git a/flang/test/Semantics/typed-subr.f90 b/flang/test/Semantics/typed-subr.f90 new file mode 100644 index 0000000..c6637c9 --- /dev/null +++ b/flang/test/Semantics/typed-subr.f90 @@ -0,0 +1,4 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 +! ERROR: SUBROUTINE prefix cannot specify a type +integer subroutine foo +end |