Skip to content

Commit

Permalink
[flang] Fix crash in statement function semantics (bug #80532) (#82702)
Browse files Browse the repository at this point in the history
When statement function expressions are analyzed, ensure that the
semantics context has a valid location set, otherwise a type spec (like
"integer::") can lead to a crash.

Fixes #80532.
  • Loading branch information
klausler committed Mar 1, 2024
1 parent bcc6ca7 commit 8f80d46
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4613,8 +4613,9 @@ evaluate::Expr<evaluate::SubscriptInteger> AnalyzeKindSelector(
SemanticsContext &context, common::TypeCategory category,
const std::optional<parser::KindSelector> &selector) {
evaluate::ExpressionAnalyzer analyzer{context};
CHECK(context.location().has_value());
auto restorer{
analyzer.GetContextualMessages().SetLocation(context.location().value())};
analyzer.GetContextualMessages().SetLocation(*context.location())};
return analyzer.AnalyzeKindSelector(category, selector);
}

Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8475,6 +8475,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
if (const auto *statement{std::get_if<
parser::Statement<common::Indirection<parser::StmtFunctionStmt>>>(
&decl.u)}) {
messageHandler().set_currStmtSource(statement->source);
AnalyzeStmtFunctionStmt(statement->statement.value());
}
}
Expand Down

0 comments on commit 8f80d46

Please sign in to comment.