diff --git a/flang/lib/Evaluate/fold-real.cpp b/flang/lib/Evaluate/fold-real.cpp --- a/flang/lib/Evaluate/fold-real.cpp +++ b/flang/lib/Evaluate/fold-real.cpp @@ -105,8 +105,14 @@ context, std::move(funcRef), &Scalar::ABS); } else if (auto *z{UnwrapExpr>(args[0])}) { return FoldElementalIntrinsic(context, std::move(funcRef), - ScalarFunc([](const Scalar &z) -> Scalar { - return z.ABS().value; + ScalarFunc([&name, &context]( + const Scalar &z) -> Scalar { + ValueWithRealFlags> y{z.ABS()}; + if (y.flags.test(RealFlag::Overflow)) { + context.messages().Say( + "complex ABS intrinsic folding overflow"_warn_en_US, name); + } + return y.value; })); } else { common::die(" unexpected argument type inside abs"); diff --git a/flang/test/Evaluate/errors01.f90 b/flang/test/Evaluate/errors01.f90 --- a/flang/test/Evaluate/errors01.f90 +++ b/flang/test/Evaluate/errors01.f90 @@ -105,5 +105,7 @@ real, parameter :: ok2 = scale(1.0, -99999) ! 0.0 !CHECK: SCALE intrinsic folding overflow real, parameter :: bad1 = scale(1.0, 99999) + !CHECK: complex ABS intrinsic folding overflow + real, parameter :: bad2 = abs(cmplx(huge(0.),huge(0.))) end subroutine end module