diff --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp --- a/flang/lib/Evaluate/fold-logical.cpp +++ b/flang/lib/Evaluate/fold-logical.cpp @@ -155,10 +155,11 @@ } } } else if (name == "isnan" || name == "__builtin_ieee_is_nan") { - using DefaultReal = Type; // Only replace the type of the function if we can do the fold if (args[0] && args[0]->UnwrapExpr() && IsActuallyConstant(*args[0]->UnwrapExpr())) { + auto restorer{context.messages().DiscardMessages()}; + using DefaultReal = Type; return FoldElementalIntrinsic(context, std::move(funcRef), ScalarFunc([](const Scalar &x) { return Scalar{x.IsNotANumber()}; 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 @@ -176,7 +176,21 @@ integer, parameter :: bad4 = dim(huge(1),-1) !CHECK: warning: HYPOT intrinsic folding overflow real, parameter :: bad5 = hypot(huge(0.), huge(0.)) + !CHECK: warning: SUM() of INTEGER(4) data overflowed + integer, parameter :: bad6 = sum([huge(1),huge(1)]) + !CHECK: warning: SUM() of REAL(4) data overflowed + real, parameter :: bad7 = sum([huge(1.),huge(1.)]) + !CHECK: warning: SUM() of COMPLEX(4) data overflowed + complex, parameter :: bad8 = sum([(huge(1.),0.),(huge(1.),0.)]) + !CHECK: warning: PRODUCT() of INTEGER(4) data overflowed + integer, parameter :: bad9 = product([huge(1),huge(1)]) + !CHECK: warning: PRODUCT() of REAL(4) data overflowed + real, parameter :: bad10 = product([huge(1.),huge(1.)]) + !CHECK: warning: PRODUCT() of COMPLEX(4) data overflowed + complex, parameter :: bad11 = product([(huge(1.),0.),(huge(1.),0.)]) !CHECK: warning: overflow on REAL(8) to REAL(4) conversion x = 1.D40 + !CHECK-NOT: warning: invalid argument + if (.not. isnan(real(z'ffffffffffffffff',8))) stop end subroutine end module