[flang-commits] [flang] 69c625b - [flang] Fix crash from bug#63099 (gfortran/regression/oldstyle_3.f90)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Jun 5 12:28:02 PDT 2023


Author: Peter Klausler
Date: 2023-06-05T12:27:50-07:00
New Revision: 69c625bf64f87641c209cf8da8ed52aa56c7336b

URL: https://github.com/llvm/llvm-project/commit/69c625bf64f87641c209cf8da8ed52aa56c7336b
DIFF: https://github.com/llvm/llvm-project/commit/69c625bf64f87641c209cf8da8ed52aa56c7336b.diff

LOG: [flang] Fix crash from bug#63099 (gfortran/regression/oldstyle_3.f90)

In InitElement() in flang/lib/Semantics/data-to-inits.cpp, don't
assume that values_.Location() can be called until after it has been
verified that values_.IsAtEnd() is not true.

Fixes https://github.com/llvm/llvm-project/issues/63099.

Differential Revision: https://reviews.llvm.org/D152183

Added: 
    

Modified: 
    flang/lib/Semantics/data-to-inits.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp
index 4fa8adbbc9a22..04088f915efc5 100644
--- a/flang/lib/Semantics/data-to-inits.cpp
+++ b/flang/lib/Semantics/data-to-inits.cpp
@@ -320,9 +320,6 @@ bool DataInitializationCompiler<DSV>::InitElement(
   bool isPointer{lastSymbol && IsPointer(*lastSymbol)};
   bool isProcPointer{lastSymbol && IsProcedurePointer(*lastSymbol)};
   evaluate::FoldingContext &context{exprAnalyzer_.GetFoldingContext()};
-  auto &messages{context.messages()};
-  auto restorer{
-      messages.SetLocation(values_.LocateSource().value_or(messages.at()))};
 
   const auto DescribeElement{[&]() {
     if (auto badDesignator{
@@ -365,6 +362,9 @@ bool DataInitializationCompiler<DSV>::InitElement(
     return false;
   }
 
+  auto &messages{context.messages()};
+  auto restorer{
+      messages.SetLocation(values_.LocateSource().value_or(messages.at()))};
   const SomeExpr *expr{*values_};
   if (!expr) {
     CHECK(exprAnalyzer_.context().AnyFatalError());


        


More information about the flang-commits mailing list