[flang-commits] [PATCH] D121163: [flang] Fix extent computation in finalization
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Mar 7 13:56:28 PST 2022
klausler created this revision.
klausler added a reviewer: schweitz.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The code that computed the extent of a dimension of a
non-allocatable/non-automatic component array during
finalization had a reversed subtraction; fix, and
use variables to make the code a little more readable.
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.413628.patch
Type: text/x-patch
Size: 829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220307/5c505b67/attachment.bin>
More information about the flang-commits
mailing list