[flang-commits] [PATCH] D154371: [flang] Warn about overflow after folding HYPOT
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Jul 3 10:24:59 PDT 2023
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The code that folds the intrinsic function HYPOT was neglecting to
warn the programmer about overflow when it occurs.
https://reviews.llvm.org/D154371
Files:
flang/lib/Evaluate/fold-real.cpp
flang/test/Evaluate/errors01.f90
Index: flang/test/Evaluate/errors01.f90
===================================================================
--- flang/test/Evaluate/errors01.f90
+++ flang/test/Evaluate/errors01.f90
@@ -163,6 +163,8 @@
real, parameter :: bad3 = dim(huge(1.),-.5*huge(1.))
!CHECK: warning: DIM intrinsic folding overflow
integer, parameter :: bad4 = dim(huge(1),-1)
+ !CHECK: warning: HYPOT intrinsic folding overflow
+ real, parameter :: bad5 = hypot(huge(0.), huge(0.))
!CHECK: warning: overflow on REAL(8) to REAL(4) conversion
x = 1.D40
end subroutine
Index: flang/lib/Evaluate/fold-real.cpp
===================================================================
--- flang/lib/Evaluate/fold-real.cpp
+++ flang/lib/Evaluate/fold-real.cpp
@@ -166,8 +166,13 @@
CHECK(args.size() == 2);
return FoldElementalIntrinsic<T, T, T>(context, std::move(funcRef),
ScalarFunc<T, T, T>(
- [](const Scalar<T> &x, const Scalar<T> &y) -> Scalar<T> {
- return x.HYPOT(y).value;
+ [&](const Scalar<T> &x, const Scalar<T> &y) -> Scalar<T> {
+ ValueWithRealFlags<Scalar<T>> result{x.HYPOT(y)};
+ if (result.flags.test(RealFlag::Overflow)) {
+ context.messages().Say(
+ "HYPOT intrinsic folding overflow"_warn_en_US);
+ }
+ return result.value;
}));
} else if (name == "max") {
return FoldMINorMAX(context, std::move(funcRef), Ordering::Greater);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154371.536833.patch
Type: text/x-patch
Size: 1502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230703/5619ed15/attachment-0001.bin>
More information about the flang-commits
mailing list