Index: flang/lib/Evaluate/fold-logical.cpp =================================================================== --- flang/lib/Evaluate/fold-logical.cpp +++ 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()}; Index: flang/test/Evaluate/errors01.f90 =================================================================== --- flang/test/Evaluate/errors01.f90 +++ flang/test/Evaluate/errors01.f90 @@ -165,5 +165,7 @@ integer, parameter :: bad4 = dim(huge(1),-1) !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