[flang-commits] [flang] [flang] Fix crash in statement function semantics (bug #80532) (PR #82702)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Feb 22 15:04:34 PST 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/issues/80532.
>From 2a69bdea4e2b8b7a410d350eb3f849193c5961a4 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Thu, 22 Feb 2024 15:01:41 -0800
Subject: [PATCH] [flang] Fix crash in statement function semantics (bug
#80532)
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 https://github.com/llvm/llvm-project/issues/80532.
---
flang/lib/Semantics/expression.cpp | 3 ++-
flang/lib/Semantics/resolve-names.cpp | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 8d817f077880b9..b957f773816b1b 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -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);
}
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..04e465acf12466 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8247,6 +8247,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());
}
}
More information about the flang-commits
mailing list