Skip to content

Commit 8f80d46

Browse files
authored
[flang] Fix crash in statement function semantics (bug #80532) (#82702)
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.
1 parent bcc6ca7 commit 8f80d46

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4613,8 +4613,9 @@ evaluate::Expr<evaluate::SubscriptInteger> AnalyzeKindSelector(
46134613
SemanticsContext &context, common::TypeCategory category,
46144614
const std::optional<parser::KindSelector> &selector) {
46154615
evaluate::ExpressionAnalyzer analyzer{context};
4616+
CHECK(context.location().has_value());
46164617
auto restorer{
4617-
analyzer.GetContextualMessages().SetLocation(context.location().value())};
4618+
analyzer.GetContextualMessages().SetLocation(*context.location())};
46184619
return analyzer.AnalyzeKindSelector(category, selector);
46194620
}
46204621

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8475,6 +8475,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
84758475
if (const auto *statement{std::get_if<
84768476
parser::Statement<common::Indirection<parser::StmtFunctionStmt>>>(
84778477
&decl.u)}) {
8478+
messageHandler().set_currStmtSource(statement->source);
84788479
AnalyzeStmtFunctionStmt(statement->statement.value());
84798480
}
84808481
}

0 commit comments

Comments
 (0)