Skip to content

Conversation

@klausler
Copy link
Contributor

@klausler klausler commented Nov 4, 2025

When an overflow or other floating-point exception occurs at compilation time while folding a conversion of a math library call to a smaller type, don't confuse the user by mentioning the conversion; just note that the exception was noted while folding the intrinsic function.

When an overflow or other floating-point exception occurs at
compilation time while folding a conversion of a math library
call to a smaller type, don't confuse the user by mentioning
the conversion; just note that the exception was noted while
folding the intrinsic function.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

When an overflow or other floating-point exception occurs at compilation time while folding a conversion of a math library call to a smaller type, don't confuse the user by mentioning the conversion; just note that the exception was noted while folding the intrinsic function.


Full diff: https://github.com/llvm/llvm-project/pull/166407.diff

3 Files Affected:

  • (modified) flang/lib/Evaluate/common.cpp (+10-9)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+1-1)
  • (modified) flang/test/Evaluate/folding33.f90 (+1-1)
diff --git a/flang/lib/Evaluate/common.cpp b/flang/lib/Evaluate/common.cpp
index ed6a0ef93b0db..119ea3c5612a5 100644
--- a/flang/lib/Evaluate/common.cpp
+++ b/flang/lib/Evaluate/common.cpp
@@ -16,25 +16,26 @@ namespace Fortran::evaluate {
 void FoldingContext::RealFlagWarnings(
     const RealFlags &flags, const char *operation) {
   static constexpr auto warning{common::UsageWarning::FoldingException};
+  if (!realFlagWarningContext_.empty()) {
+    // Override 'operation' with a string like
+    // "compilation-time evaluation of a call to '...'"
+    operation = realFlagWarningContext_.c_str();
+  }
   if (flags.test(RealFlag::Overflow)) {
-    Warn(warning, "overflow on %s%s"_warn_en_US, operation,
-        realFlagWarningContext_);
+    Warn(warning, "overflow on %s"_warn_en_US, operation);
   }
   if (flags.test(RealFlag::DivideByZero)) {
     if (std::strcmp(operation, "division") == 0) {
-      Warn(warning, "division by zero%s"_warn_en_US, realFlagWarningContext_);
+      Warn(warning, "division by zero"_warn_en_US);
     } else {
-      Warn(warning, "division by zero on %s%s"_warn_en_US, operation,
-          realFlagWarningContext_);
+      Warn(warning, "division by zero on %s"_warn_en_US, operation);
     }
   }
   if (flags.test(RealFlag::InvalidArgument)) {
-    Warn(warning, "invalid argument on %s%s"_warn_en_US, operation,
-        realFlagWarningContext_);
+    Warn(warning, "invalid argument on %s"_warn_en_US, operation);
   }
   if (flags.test(RealFlag::Underflow)) {
-    Warn(warning, "underflow on %s%s"_warn_en_US, operation,
-        realFlagWarningContext_);
+    Warn(warning, "underflow on %s"_warn_en_US, operation);
   }
 }
 
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index d8af5246fabdd..54726ac539d60 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -1052,7 +1052,7 @@ std::optional<HostRuntimeWrapper> GetHostRuntimeWrapper(const std::string &name,
                 .value());
       }
       auto restorer{context.SetRealFlagWarningContext(
-          " after folding a call to '"s + name + "'"s)};
+          "compilation-time evaluation of a call to '"s + name + "'"s)};
       return Fold(context,
           ConvertToType(
               resultType, hostFolderWithChecks(context, std::move(args)))
diff --git a/flang/test/Evaluate/folding33.f90 b/flang/test/Evaluate/folding33.f90
index fb5a23cf1f209..299cb7e1731a5 100644
--- a/flang/test/Evaluate/folding33.f90
+++ b/flang/test/Evaluate/folding33.f90
@@ -1,4 +1,4 @@
 !RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
-!CHECK: warning: overflow on REAL(4) to REAL(2) conversion after folding a call to 'exp' [-Wfolding-exception]
+!CHECK: warning: overflow on compilation-time evaluation of a call to 'exp' [-Wfolding-exception]
 print *, exp((11.265625_2,1._2))
 end

@klausler klausler merged commit 3d0ae1e into llvm:main Nov 7, 2025
13 checks passed
@klausler klausler deleted the steve2 branch November 7, 2025 16:41
vinay-deshmukh pushed a commit to vinay-deshmukh/llvm-project that referenced this pull request Nov 8, 2025
When an overflow or other floating-point exception occurs at compilation
time while folding a conversion of a math library call to a smaller
type, don't confuse the user by mentioning the conversion; just note
that the exception was noted while folding the intrinsic function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants