[flang-commits] [flang] b2b4379 - [flang] Warn about overflow after folding HYPOT
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Jul 3 11:21:42 PDT 2023
Author: Peter Klausler
Date: 2023-07-03T11:21:32-07:00
New Revision: b2b43794b977d0a4b11bddb9fee4f04cbddce25d
URL: https://github.com/llvm/llvm-project/commit/b2b43794b977d0a4b11bddb9fee4f04cbddce25d
DIFF: https://github.com/llvm/llvm-project/commit/b2b43794b977d0a4b11bddb9fee4f04cbddce25d.diff
LOG: [flang] Warn about overflow after folding HYPOT
The code that folds the intrinsic function HYPOT was neglecting to
warn the programmer about overflow when it occurs.
Differential Revision: https://reviews.llvm.org/D154371
Added:
Modified:
flang/lib/Evaluate/fold-real.cpp
flang/test/Evaluate/errors01.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-real.cpp b/flang/lib/Evaluate/fold-real.cpp
index a20f7355861aa5..038ec95a332b82 100644
--- a/flang/lib/Evaluate/fold-real.cpp
+++ b/flang/lib/Evaluate/fold-real.cpp
@@ -166,8 +166,13 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
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);
diff --git a/flang/test/Evaluate/errors01.f90 b/flang/test/Evaluate/errors01.f90
index 1ae6c62a4e3ee2..be8700405673c1 100644
--- a/flang/test/Evaluate/errors01.f90
+++ b/flang/test/Evaluate/errors01.f90
@@ -163,6 +163,8 @@ subroutine warnings
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
More information about the flang-commits
mailing list