[flang-commits] [flang] 041080f - [flang] Fix extent computation in finalization
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Mar 9 09:01:11 PST 2022
Author: Peter Klausler
Date: 2022-03-09T09:01:02-08:00
New Revision: 041080fc9b7a245967f512923dae9d6af7cfbc57
URL: https://github.com/llvm/llvm-project/commit/041080fc9b7a245967f512923dae9d6af7cfbc57
DIFF: https://github.com/llvm/llvm-project/commit/041080fc9b7a245967f512923dae9d6af7cfbc57.diff
LOG: [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
Added:
Modified:
flang/runtime/derived.cpp
Removed:
################################################################################
diff --git a/flang/runtime/derived.cpp b/flang/runtime/derived.cpp
index f9e34b21c800f..bb47f6b7a3292 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()};
More information about the flang-commits
mailing list