[flang-commits] [PATCH] D95831: [flang] Detect UBOUND() error on assumed-size array

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Feb 2 11:38:08 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc6fadf70828: [flang] Detect UBOUND() error on assumed-size array (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95831/new/

https://reviews.llvm.org/D95831

Files:
  flang/lib/Evaluate/fold-integer.cpp
  flang/test/Evaluate/folding19.f90
  flang/test/Semantics/spec-expr.f90


Index: flang/test/Semantics/spec-expr.f90
===================================================================
--- flang/test/Semantics/spec-expr.f90
+++ flang/test/Semantics/spec-expr.f90
@@ -79,7 +79,7 @@
 subroutine s7bi(assumedArg)
   integer, dimension(2, *) :: assumedArg
   real, dimension(ubound(assumedArg, 1)) :: realArray1
-  ! Should be an error since 2 is the last dimension of an assumed-size array
+  !ERROR: DIM=2 dimension is out of range for rank-2 assumed-size array
   real, dimension(ubound(assumedArg, 2)) :: realArray2
 end subroutine s7bi
 
Index: flang/test/Evaluate/folding19.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/folding19.f90
@@ -0,0 +1,22 @@
+! RUN: not %f18 %s 2>&1 | FileCheck %s
+! Check errors found in folding
+! TODO: test others emitted from flang/lib/Evaluate
+module m
+ contains
+  subroutine s1(a,b)
+    real :: a(*), b(:)
+    !CHECK: error: DIM=1 dimension is out of range for rank-1 assumed-size array
+    integer :: ub1(ubound(a,1))
+    !CHECK-NOT: error: DIM=1 dimension is out of range for rank-1 assumed-size array
+    integer :: lb1(lbound(a,1))
+    !CHECK: error: DIM=0 dimension is out of range for rank-1 array
+    integer :: ub2(ubound(a,0))
+    !CHECK: error: DIM=2 dimension is out of range for rank-1 array
+    integer :: ub3(ubound(a,2))
+    !CHECK: error: DIM=0 dimension is out of range for rank-1 array
+    integer :: lb2(lbound(b,0))
+    !CHECK: error: DIM=2 dimension is out of range for rank-1 array
+    integer :: lb3(lbound(b,2))
+  end subroutine
+end module
+
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -23,7 +23,7 @@
         if (auto dim64{GetInt64Arg(args[1])}) {
           if (*dim64 < 1 || *dim64 > rank) {
             context.messages().Say("DIM=%jd dimension is out of range for "
-                                   "rank-%d array"_en_US,
+                                   "rank-%d array"_err_en_US,
                 *dim64, rank);
             return MakeInvalidIntrinsic<T>(std::move(funcRef));
           } else {
@@ -78,7 +78,7 @@
         if (auto dim64{GetInt64Arg(args[1])}) {
           if (*dim64 < 1 || *dim64 > rank) {
             context.messages().Say("DIM=%jd dimension is out of range for "
-                                   "rank-%d array"_en_US,
+                                   "rank-%d array"_err_en_US,
                 *dim64, rank);
             return MakeInvalidIntrinsic<T>(std::move(funcRef));
           } else {
@@ -95,8 +95,11 @@
         if (symbol.Rank() == rank) {
           takeBoundsFromShape = false;
           if (dim) {
-            if (semantics::IsAssumedSizeArray(symbol) && *dim == rank) {
-              return Expr<T>{-1};
+            if (semantics::IsAssumedSizeArray(symbol) && *dim == rank - 1) {
+              context.messages().Say("DIM=%jd dimension is out of range for "
+                                     "rank-%d assumed-size array"_err_en_US,
+                  rank, rank);
+              return MakeInvalidIntrinsic<T>(std::move(funcRef));
             } else if (auto ub{GetUpperBound(context, *named, *dim)}) {
               return Fold(context, ConvertToType<T>(std::move(*ub)));
             }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95831.320866.patch
Type: text/x-patch
Size: 3379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210202/816ed951/attachment.bin>


More information about the flang-commits mailing list