mirror of
https://github.com/intel/llvm.git
synced 2026-01-21 04:14:03 +08:00
[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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user