[flang-commits] [PATCH] D153799: [flang] Handle empty array references in DATA statements

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jun 26 11:55:09 PDT 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

When an array reference in a DATA statement is empty due to an   
empty vector subscript or a section lower bound being higher than
its upper bound with a positive stride (or lower with negative), 
ensure that isEmpty() is correct afterwards so that such an empty  
array reference doesn't terminate processing of that DATA statement
block.

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


https://reviews.llvm.org/D153799

Files:
  flang/lib/Evaluate/fold-designator.cpp
  flang/test/Semantics/data05.f90


Index: flang/test/Semantics/data05.f90
===================================================================
--- flang/test/Semantics/data05.f90
+++ flang/test/Semantics/data05.f90
@@ -89,4 +89,8 @@
     procedure(rfunc), pointer :: pp ! CHECK: pp, EXTERNAL, POINTER (Function, InDataStmt) size=8 offset=0: ProcEntity rfunc => rfunc2
     data pp/rfunc2/
   end subroutine
+  subroutine s13
+    integer j(2)
+    data j(2:1), j(1:2) /1,2/ ! CHECK: j (InDataStmt) size=8 offset=0: ObjectEntity type: INTEGER(4) shape: 1_8:2_8 init:[INTEGER(4)::1_4,2_4]
+  end subroutine
 end module
Index: flang/lib/Evaluate/fold-designator.cpp
===================================================================
--- flang/lib/Evaluate/fold-designator.cpp
+++ flang/lib/Evaluate/fold-designator.cpp
@@ -90,6 +90,8 @@
                               result->Augment((at - lower) * stride);
                               which = quotient;
                               return true;
+                            } else {
+                              isEmpty_ = true;
                             }
                           }
                           return false;
@@ -100,16 +102,20 @@
                           auto end{ToInt64(Fold(context_,
                               triplet.upper().value_or(ExtentExpr{upper})))};
                           auto step{ToInt64(Fold(context_, triplet.stride()))};
-                          if (start && end && step && *step != 0) {
-                            ConstantSubscript range{
-                                (*end - *start + *step) / *step};
-                            if (range > 0) {
-                              auto quotient{which / range};
-                              auto remainder{which - range * quotient};
-                              auto j{*start + remainder * *step};
-                              result->Augment((j - lower) * stride);
-                              which = quotient;
-                              return true;
+                          if (start && end && step) {
+                            if (*step != 0) {
+                              ConstantSubscript range{
+                                  (*end - *start + *step) / *step};
+                              if (range > 0) {
+                                auto quotient{which / range};
+                                auto remainder{which - range * quotient};
+                                auto j{*start + remainder * *step};
+                                result->Augment((j - lower) * stride);
+                                which = quotient;
+                                return true;
+                              } else {
+                                isEmpty_ = true;
+                              }
                             }
                           }
                           return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153799.534685.patch
Type: text/x-patch
Size: 2866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230626/b1fdafd1/attachment-0001.bin>


More information about the flang-commits mailing list