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

via flang-commits flang-commits at lists.llvm.org
Fri Mar 1 15:10:51 PST 2024


Author: Peter Klausler
Date: 2024-03-01T15:10:47-08:00
New Revision: 8f80d466d580d0fb97383eac8a2d7d9a1e3f15f4

URL: https://github.com/llvm/llvm-project/commit/8f80d466d580d0fb97383eac8a2d7d9a1e3f15f4
DIFF: https://github.com/llvm/llvm-project/commit/8f80d466d580d0fb97383eac8a2d7d9a1e3f15f4.diff

LOG: [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 https://github.com/llvm/llvm-project/issues/80532.

Added: 
    

Modified: 
    flang/lib/Semantics/expression.cpp
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
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 7f9909ee937d59..eb61a76f10874c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -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());
     }
   }


        


More information about the flang-commits mailing list