[flang-commits] [flang] 58d7484 - [flang] Fix overflow detection for folding SUM/PRODUCT
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Jul 3 13:03:51 PDT 2023
Author: Peter Klausler
Date: 2023-07-03T12:49:46-07:00
New Revision: 58d7484360e7987fec6f893da4b3e36da04bb643
URL: https://github.com/llvm/llvm-project/commit/58d7484360e7987fec6f893da4b3e36da04bb643
DIFF: https://github.com/llvm/llvm-project/commit/58d7484360e7987fec6f893da4b3e36da04bb643.diff
LOG: [flang] Fix overflow detection for folding SUM/PRODUCT
The overflow detection code in the templates that fold SUM and PRODUCT
was checking for overflow before performing the reduction, not after.
Fix and add tests.
Differential Revision: https://reviews.llvm.org/D154374
Added:
Modified:
flang/lib/Evaluate/fold-reduction.h
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-reduction.h b/flang/lib/Evaluate/fold-reduction.h
index 89b5141b2f130c..b76cecffaf1c63 100644
--- a/flang/lib/Evaluate/fold-reduction.h
+++ b/flang/lib/Evaluate/fold-reduction.h
@@ -260,12 +260,12 @@ static Expr<T> FoldProduct(
element = prod.value;
}
}};
+ auto result{Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)}};
if (overflow) {
context.messages().Say(
"PRODUCT() of %s data overflowed"_warn_en_US, T::AsFortran());
- } else {
- return Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)};
}
+ return result;
}
return Expr<T>{std::move(ref)};
}
@@ -301,12 +301,12 @@ static Expr<T> FoldSum(FoldingContext &context, FunctionRef<T> &&ref) {
element = sum.value;
}
}};
+ auto result{Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)}};
if (overflow) {
context.messages().Say(
"SUM() of %s data overflowed"_warn_en_US, T::AsFortran());
- } else {
- return Expr<T>{DoReduction<T>(*array, dim, identity, accumulator)};
}
+ return result;
}
return Expr<T>{std::move(ref)};
}
More information about the flang-commits
mailing list