Skip to content

Commit 3d0ae1e

Browse files
authored
[flang] Improve warning text (#166407)
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.
1 parent b3b4ea1 commit 3d0ae1e

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

flang/lib/Evaluate/common.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ namespace Fortran::evaluate {
1616
void FoldingContext::RealFlagWarnings(
1717
const RealFlags &flags, const char *operation) {
1818
static constexpr auto warning{common::UsageWarning::FoldingException};
19+
if (!realFlagWarningContext_.empty()) {
20+
// Override 'operation' with a string like
21+
// "compilation-time evaluation of a call to '...'"
22+
operation = realFlagWarningContext_.c_str();
23+
}
1924
if (flags.test(RealFlag::Overflow)) {
20-
Warn(warning, "overflow on %s%s"_warn_en_US, operation,
21-
realFlagWarningContext_);
25+
Warn(warning, "overflow on %s"_warn_en_US, operation);
2226
}
2327
if (flags.test(RealFlag::DivideByZero)) {
2428
if (std::strcmp(operation, "division") == 0) {
25-
Warn(warning, "division by zero%s"_warn_en_US, realFlagWarningContext_);
29+
Warn(warning, "division by zero"_warn_en_US);
2630
} else {
27-
Warn(warning, "division by zero on %s%s"_warn_en_US, operation,
28-
realFlagWarningContext_);
31+
Warn(warning, "division by zero on %s"_warn_en_US, operation);
2932
}
3033
}
3134
if (flags.test(RealFlag::InvalidArgument)) {
32-
Warn(warning, "invalid argument on %s%s"_warn_en_US, operation,
33-
realFlagWarningContext_);
35+
Warn(warning, "invalid argument on %s"_warn_en_US, operation);
3436
}
3537
if (flags.test(RealFlag::Underflow)) {
36-
Warn(warning, "underflow on %s%s"_warn_en_US, operation,
37-
realFlagWarningContext_);
38+
Warn(warning, "underflow on %s"_warn_en_US, operation);
3839
}
3940
}
4041

flang/lib/Evaluate/intrinsics-library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ std::optional<HostRuntimeWrapper> GetHostRuntimeWrapper(const std::string &name,
10521052
.value());
10531053
}
10541054
auto restorer{context.SetRealFlagWarningContext(
1055-
" after folding a call to '"s + name + "'"s)};
1055+
"compilation-time evaluation of a call to '"s + name + "'"s)};
10561056
return Fold(context,
10571057
ConvertToType(
10581058
resultType, hostFolderWithChecks(context, std::move(args)))

flang/test/Evaluate/folding33.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
!RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
2-
!CHECK: warning: overflow on REAL(4) to REAL(2) conversion after folding a call to 'exp' [-Wfolding-exception]
2+
!CHECK: warning: overflow on compilation-time evaluation of a call to 'exp' [-Wfolding-exception]
33
print *, exp((11.265625_2,1._2))
44
end

0 commit comments

Comments
 (0)