[flang-commits] [flang] 9520b6c - [flang] Fix a crash when cosubscript list is empty

Pete Steinfeld via flang-commits flang-commits at lists.llvm.org
Wed Jul 8 10:11:54 PDT 2020


Author: Pete Steinfeld
Date: 2020-07-08T10:11:34-07:00
New Revision: 9520b6c8ab63061e1734deef8614eaa60f704dc9

URL: https://github.com/llvm/llvm-project/commit/9520b6c8ab63061e1734deef8614eaa60f704dc9
DIFF: https://github.com/llvm/llvm-project/commit/9520b6c8ab63061e1734deef8614eaa60f704dc9.diff

LOG: [flang] Fix a crash when cosubscript list is empty

Summary:
When there are errors in the evaluation of every cosubscript expression in a
coindexed object, the compiler would crash.  I fixed this by just checking to
see if there were errors in the evaluation of the cosubscripts before
constructing the `DataRef` for the coindexed object.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

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

Added: 
    

Modified: 
    flang/lib/Semantics/expression.cpp
    flang/test/Semantics/resolve94.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 71911718c087..dca0f6259bbe 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -1089,15 +1089,17 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::CoindexedNamedObject &x) {
         std::get<std::list<parser::ImageSelectorSpec>>(x.imageSelector.t)) {
       std::visit(
           common::visitors{
-              [&](const auto &x) {Analyze(x.v); },
+              [&](const auto &x) { Analyze(x.v); },
           },
           imageSelSpec.u);
     }
     // Reverse the chain of symbols so that the base is first and coarray
     // ultimate component is last.
-    return Designate(
-        DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()},
-            std::move(subscripts), std::move(cosubscripts)}});
+    if (cosubsOk) {
+      return Designate(
+          DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()},
+              std::move(subscripts), std::move(cosubscripts)}});
+    }
   }
   return std::nullopt;
 }

diff  --git a/flang/test/Semantics/resolve94.f90 b/flang/test/Semantics/resolve94.f90
index b38037e2d530..bf91d6151460 100644
--- a/flang/test/Semantics/resolve94.f90
+++ b/flang/test/Semantics/resolve94.f90
@@ -13,6 +13,7 @@ subroutine s1()
   integer, dimension(4) :: intArray
   integer :: intScalarCoarray[*]
   integer :: intCoarray[3, 4, *]
+  integer :: smallIntCoarray[4, *]
   intCoVar = 343
   ! OK
   rVar1 = rCoarray[1,2,3]
@@ -20,6 +21,8 @@ subroutine s1()
   rVar1 = rCoarray[1,2]
   !ERROR: Must have INTEGER type, but is REAL(4)
   rVar1 = rCoarray[1,2,3.4]
+  !ERROR: Must have INTEGER type, but is REAL(4)
+  iVar1 = smallIntCoarray[3.4]
   !ERROR: Must be a scalar value, but is a rank-1 array
   rVar1 = rCoarray[1,intArray,3]
   ! OK


        


More information about the flang-commits mailing list