[PATCH] D87799: [flang] Substrings with lower bound greater than upper bound

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 14:57:34 PDT 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd3eb3f33239: [flang] Substrings with lower bound greater than upper bound (authored by PeteSteinfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87799

Files:
  flang/lib/Evaluate/variable.cpp
  flang/test/Semantics/resolve49.f90


Index: flang/test/Semantics/resolve49.f90
===================================================================
--- flang/test/Semantics/resolve49.f90
+++ flang/test/Semantics/resolve49.f90
@@ -17,6 +17,7 @@
   end type
   character :: a(10)
   character :: b(5)
+  character :: c(0)
   integer :: n
   n = 3
   b = a(n:7)
@@ -26,6 +27,7 @@
   a(n+3:) = b
   a(:n+2) = b
   n = iachar(1_'ABCDEFGHIJ'(1:1))
+  c = 'ABCDEFGHIJ'(1:0)
 end
 
 ! Test pointer assignment with bounds
Index: flang/lib/Evaluate/variable.cpp
===================================================================
--- flang/lib/Evaluate/variable.cpp
+++ flang/lib/Evaluate/variable.cpp
@@ -204,9 +204,11 @@
       *ubi = *length;
     }
     if (lbi && literal) {
-      CHECK(*ubi >= *lbi);
       auto newStaticData{StaticDataObject::Create()};
-      auto items{*ubi - *lbi + 1};
+      auto items{0}; // If the lower bound is greater, the length is 0
+      if (*ubi >= *lbi) {
+        items = *ubi - *lbi + 1;
+      }
       auto width{(*literal)->itemBytes()};
       auto bytes{items * width};
       auto startByte{(*lbi - 1) * width};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87799.292357.patch
Type: text/x-patch
Size: 1114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200916/9525c0b7/attachment.bin>


More information about the llvm-commits mailing list