diff options
author | Peter Klausler <pklausler@nvidia.com> | 2022-03-01 22:50:49 +0300 |
---|---|---|
committer | Peter Klausler <pklausler@nvidia.com> | 2022-03-09 20:01:02 +0300 |
commit | 041080fc9b7a245967f512923dae9d6af7cfbc57 (patch) | |
tree | e1352ead89a40ed98acd1341dcde33cc9b7ee50a /flang | |
parent | 3925f98de4ac9e4eeeb82b8f9d442daec9018b61 (diff) |
[flang] Fix extent computation in finalization
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.
Differential Revision: https://reviews.llvm.org/D121163
Diffstat (limited to 'flang')
-rw-r--r-- | flang/runtime/derived.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/flang/runtime/derived.cpp b/flang/runtime/derived.cpp index f9e34b21c800..bb47f6b7a329 100644 --- a/flang/runtime/derived.cpp +++ b/flang/runtime/derived.cpp @@ -188,8 +188,10 @@ void Finalize( 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()}; |