[flang-commits] [flang] ba038a3 - [flang] Do not ICE on out-of-range data statement designator

Mike Kashkarov via flang-commits flang-commits at lists.llvm.org
Thu Apr 14 02:52:00 PDT 2022


Author: Mike Kashkarov
Date: 2022-04-14T12:51:55+03:00
New Revision: ba038a308021203d9d565b96c2eea5bd2f231ce2

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

LOG: [flang] Do not ICE on out-of-range data statement designator

Print error message instead of assert trigger.

Reviewed By: klausler

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

Added: 
    

Modified: 
    flang/lib/Evaluate/fold-designator.cpp
    flang/test/Semantics/data06.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/fold-designator.cpp b/flang/lib/Evaluate/fold-designator.cpp
index f3e1cf40cb8ac..e00bb09a3c74a 100644
--- a/flang/lib/Evaluate/fold-designator.cpp
+++ b/flang/lib/Evaluate/fold-designator.cpp
@@ -298,7 +298,9 @@ static std::optional<DataRef> OffsetToDataRef(FoldingContext &context,
 // Reconstructs a Designator from a symbol, an offset, and a size.
 std::optional<Expr<SomeType>> OffsetToDesignator(FoldingContext &context,
     const Symbol &baseSymbol, ConstantSubscript offset, std::size_t size) {
-  CHECK(offset >= 0);
+  if (offset < 0) {
+    return std::nullopt;
+  }
   if (std::optional<DataRef> dataRef{
           OffsetToDataRef(context, NamedEntity{baseSymbol}, offset, size)}) {
     const Symbol &symbol{dataRef->GetLastSymbol()};

diff  --git a/flang/test/Semantics/data06.f90 b/flang/test/Semantics/data06.f90
index bf32fd8f3404b..08cdd147a084b 100644
--- a/flang/test/Semantics/data06.f90
+++ b/flang/test/Semantics/data06.f90
@@ -28,6 +28,9 @@ subroutine s1
   integer :: a4(3)
   !ERROR: DATA statement designator 'a4(5_8)' is out of range
   data (a4(j),j=1,5,2) /3*222/
+  integer :: a5(3)
+  !ERROR: DATA statement designator 'a5(-2_8)' is out of range
+  data       a5(-2) / 1 /
   interface
     real function rfunc(x)
       real, intent(in) :: x


        


More information about the flang-commits mailing list