[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
This commit is contained in:
Peter Klausler
2023-06-28 16:08:54 -07:00
parent ebec53e2d7
commit b2b43794b9
2 changed files with 9 additions and 2 deletions

View File

@@ -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);

View File

@@ -163,6 +163,8 @@ module m
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