[flang-commits] [flang] [flang] Fix crash in statement function semantics (bug #80532) (PR #82702)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 22 15:05:04 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/82702.diff


2 Files Affected:

- (modified) flang/lib/Semantics/expression.cpp (+2-1) 
- (modified) flang/lib/Semantics/resolve-names.cpp (+1) 


``````````diff
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());
     }
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/82702


More information about the flang-commits mailing list