[flang-commits] [PATCH] D121163: [flang] Fix extent computation in finalization

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 9 09:01:21 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG041080fc9b7a: [flang] Fix extent computation in finalization (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121163

Files:
  flang/runtime/derived.cpp


Index: flang/runtime/derived.cpp
===================================================================
--- flang/runtime/derived.cpp
+++ flang/runtime/derived.cpp
@@ -188,8 +188,10 @@
       SubscriptValue extent[maxRank];
       const typeInfo::Value *bounds{comp.bounds()};
       for (int dim{0}; dim < comp.rank(); ++dim) {
-        extent[dim] = bounds[2 * dim].GetValue(&descriptor).value_or(0) -
-            bounds[2 * dim + 1].GetValue(&descriptor).value_or(0) + 1;
+        SubscriptValue lb{bounds[2 * dim].GetValue(&descriptor).value_or(0)};
+        SubscriptValue ub{
+            bounds[2 * dim + 1].GetValue(&descriptor).value_or(0)};
+        extent[dim] = ub >= lb ? ub - lb + 1 : 0;
       }
       StaticDescriptor<maxRank, true, 0> staticDescriptor;
       Descriptor &compDesc{staticDescriptor.descriptor()};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121163.414118.patch
Type: text/x-patch
Size: 829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220309/764faa89/attachment-0001.bin>


More information about the flang-commits mailing list