[clang] Fix INF/NAN warning. (PR #80290)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 1 05:31:46 PST 2024
https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/80290
None
>From 529879c78ae4c1bf4d04110b543f37c1d1af20f7 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Thu, 1 Feb 2024 05:26:00 -0800
Subject: [PATCH] Fix INF/NAN warning.
---
.../clang/Basic/DiagnosticCommonKinds.td | 4 +-
clang/include/clang/Lex/Preprocessor.h | 21 ++-
clang/lib/Lex/PPDirectives.cpp | 2 +-
clang/lib/Lex/Preprocessor.cpp | 6 +-
clang/lib/Sema/SemaChecking.cpp | 10 +-
.../Sema/warn-infinity-nan-disabled-lnx.cpp | 172 +++++++++++-------
.../Sema/warn-infinity-nan-disabled-win.cpp | 171 ++++++++++-------
7 files changed, 241 insertions(+), 145 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index b1bada65cb6b2..ccae70a0fdbac 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -72,7 +72,9 @@ def warn_pragma_debug_unexpected_argument : Warning<
def warn_fp_nan_inf_when_disabled : Warning<
"use of %select{infinity|NaN}0%select{| via a macro}1 is undefined behavior "
- "due to the currently enabled floating-point options">,
+ "due to the currently enabled floating-point options%select{|; mix of safe "
+ "and unsafe math options are used. Check the order of you command line "
+ "arguments}2">,
InGroup<DiagGroup<"nan-infinity-disabled">>;
}
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 9d0d53129a12d..dac5a46f73749 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2838,7 +2838,8 @@ class Preprocessor {
return AnnotationInfos.find(II)->second;
}
- void emitMacroExpansionWarnings(const Token &Identifier) const {
+ void emitMacroExpansionWarnings(const Token &Identifier,
+ bool IsIfnDef = false) const {
IdentifierInfo *Info = Identifier.getIdentifierInfo();
if (Info->isDeprecatedMacro())
emitMacroDeprecationWarning(Identifier);
@@ -2847,12 +2848,15 @@ class Preprocessor {
!SourceMgr.isInMainFile(Identifier.getLocation()))
emitRestrictExpansionWarning(Identifier);
- if (Info->getName() == "INFINITY")
- if (getLangOpts().NoHonorInfs)
- emitRestrictInfNaNWarning(Identifier, 0);
- if (Info->getName() == "NAN")
- if (getLangOpts().NoHonorNaNs)
- emitRestrictInfNaNWarning(Identifier, 1);
+ if (!IsIfnDef) {
+ bool UnsafeMath = getLangOpts().UnsafeFPMath;
+ if (Info->getName() == "INFINITY")
+ if (getLangOpts().NoHonorInfs)
+ emitRestrictInfNaNWarning(Identifier, 0, UnsafeMath);
+ if (Info->getName() == "NAN")
+ if (getLangOpts().NoHonorNaNs)
+ emitRestrictInfNaNWarning(Identifier, 1, UnsafeMath);
+ }
}
static void processPathForFileMacro(SmallVectorImpl<char> &Path,
@@ -2869,7 +2873,8 @@ class Preprocessor {
void emitRestrictExpansionWarning(const Token &Identifier) const;
void emitFinalMacroWarning(const Token &Identifier, bool IsUndef) const;
void emitRestrictInfNaNWarning(const Token &Identifier,
- unsigned DiagSelection) const;
+ unsigned DiagSelection,
+ bool UnsafeMath) const;
/// This boolean state keeps track if the current scanned token (by this PP)
/// is in an "-Wunsafe-buffer-usage" opt-out region. Assuming PP scans a
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 9f82a6d073e3b..17a59677e2de4 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3288,7 +3288,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
return;
}
- emitMacroExpansionWarnings(MacroNameTok);
+ emitMacroExpansionWarnings(MacroNameTok, true);
// Check to see if this is the last token on the #if[n]def line.
CheckEndOfDirective(isIfndef ? "ifndef" : "ifdef");
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 031ed1e16bb8f..635d052070146 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -1466,8 +1466,10 @@ void Preprocessor::emitRestrictExpansionWarning(const Token &Identifier) const {
}
void Preprocessor::emitRestrictInfNaNWarning(const Token &Identifier,
- unsigned DiagSelection) const {
- Diag(Identifier, diag::warn_fp_nan_inf_when_disabled) << DiagSelection << 1;
+ unsigned DiagSelection,
+ bool UnsafeMath) const {
+ Diag(Identifier, diag::warn_fp_nan_inf_when_disabled)
+ << DiagSelection << 1 << UnsafeMath;
}
void Preprocessor::emitFinalMacroWarning(const Token &Identifier,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7b877da1a928f..62a0dbd6d7ea2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9132,7 +9132,7 @@ bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID) {
if (BuiltinID == Builtin::BI__builtin_isunordered &&
TheCall->getFPFeaturesInEffect(getLangOpts()).getNoHonorNaNs())
Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
- << 1 << 0 << TheCall->getSourceRange();
+ << 1 << 0 << 0;
ExprResult OrigArg0 = TheCall->getArg(0);
ExprResult OrigArg1 = TheCall->getArg(1);
@@ -9178,12 +9178,12 @@ bool Sema::SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
BuiltinID == Builtin::BI__builtin_isinf ||
BuiltinID == Builtin::BI__builtin_isinf_sign))
Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
- << 0 << 0 << TheCall->getSourceRange();
+ << 0 << 0 << 0;
if (FPO.getNoHonorNaNs() && (BuiltinID == Builtin::BI__builtin_isnan ||
BuiltinID == Builtin::BI__builtin_isunordered))
Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
- << 1 << 0 << TheCall->getSourceRange();
+ << 1 << 0 << 0;
bool IsFPClass = NumArgs == 2;
@@ -12938,13 +12938,13 @@ void Sema::CheckInfNaNFunction(const CallExpr *Call,
(Call->getBuiltinCallee() == Builtin::BI__builtin_nanf)) &&
FPO.getNoHonorNaNs())
Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
- << 1 << 0 << Call->getSourceRange();
+ << 1 << 0 << 0;
else if ((IsStdFunction(FDecl, "isinf") ||
(IsStdFunction(FDecl, "isfinite") ||
(FDecl->getIdentifier() && FDecl->getName() == "infinity"))) &&
FPO.getNoHonorInfs())
Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
- << 0 << 0 << Call->getSourceRange();
+ << 0 << 0 << 0;
}
// Warn when using the wrong abs() function.
diff --git a/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp b/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
index 8a610fa0e737e..be29f38e3b43e 100644
--- a/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
+++ b/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
@@ -9,8 +9,12 @@
// RUN: %clang_cc1 -x c++ -verify=no-nan -triple powerpc64le-unknown-unknown %s \
// RUN: -menable-no-nans
+// RUN: %clang_cc1 -x c++ -verify=no-inf-no-nan-mix-mode -triple powerpc64le-unknown-unknown %s \
+// RUN: -menable-no-infs -menable-no-nans -funsafe-math-optimizations
+
// no-fast-no-diagnostics
+
int isunorderedf (float x, float y);
extern "C++" {
namespace std __attribute__((__visibility__("default"))) {
@@ -69,108 +73,148 @@ class numeric_limits<double> {
int compareit(float a, float b) {
volatile int i, j, k, l, m, n, o, p;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
i = a == INFINITY;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = INFINITY == a;
-// no-inf-no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
i = a == NAN;
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
j = NAN == a;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = INFINITY <= a;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = INFINITY < a;
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
j = a > NAN;
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
j = a >= NAN;
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
k = std::isinf(a);
-// no-inf-no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point option}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point option}}
+// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
l = std::isnan(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
o = std::isfinite(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
m = __builtin_isinf(a);
-// no-inf-no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
n = __builtin_isnan(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
p = __builtin_isfinite(a);
- // These should NOT warn, since they are not using NaN or infinity.
- j = a > 1.1;
- j = b < 1.1;
- j = a >= 1.1;
- j = b <= 1.1;
- j = isunorderedf(a, b);
-
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
j = isunorderedf(a, NAN);
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = isunorderedf(a, INFINITY);
-// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +9 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +8 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +7 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
i = std::isunordered(a, NAN);
-// no-inf-no-nan-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +7 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +5 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-mix-mode-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
i = std::isunordered(a, INFINITY);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
double y = i * numeric_limits<double>::infinity();
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
j = numeric_limits<float>::infinity();
- return 0;
+ // These should NOT warn, since they are not using NaN or infinity.
+ j = a > 1.1;
+ j = b < 1.1;
+ j = a >= 1.1;
+ j = b <= 1.1;
+ j = isunorderedf(a, b);
+#ifndef INFINITY
+ j = a;
+#endif
+#ifndef NAN
+ j = b;
+#endif
+#ifdef INFINITY
+ j = a;
+#endif
+#ifdef NAN
+ j = b;
+#endif
+ return 0;
}
diff --git a/clang/test/Sema/warn-infinity-nan-disabled-win.cpp b/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
index 19a575386e329..31fb55635af6e 100644
--- a/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
+++ b/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
@@ -12,6 +12,9 @@
// RUN: %clang_cc1 -x c++ -verify=no-nan -triple powerpc64le-unknown-unknown %s \
// RUN: -menable-no-nans
+// RUN: %clang_cc1 -x c++ -verify=no-inf-no-nan-mix-mode -triple powerpc64le-unknown-unknown %s \
+// RUN: -menable-no-infs -menable-no-nans -funsafe-math-optimizations
+
// no-fast-no-diagnostics
int isunorderedf (float x, float y);
@@ -72,108 +75,148 @@ class numeric_limits<double> {
int compareit(float a, float b) {
volatile int i, j, k, l, m, n, o, p;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
i = a == INFINITY;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = INFINITY == a;
-// no-inf-no-nan-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
i = a == NAN;
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = NAN == a;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = INFINITY <= a;
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
- j = INFINITY < a;
-
-// no-inf-no-nan-warning at +4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+ j = INFINITY < a;
+
+// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = a > NAN;
-// no-inf-no-nan-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = a >= NAN;
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
k = std::isinf(a);
-// no-inf-no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
l = std::isnan(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
o = std::isfinite(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
m = __builtin_isinf(a);
-// no-inf-no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
n = __builtin_isnan(a);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
p = __builtin_isfinite(a);
- // These should NOT warn, since they are not using NaN or infinity.
- j = a > 1.1;
- j = b < 1.1;
- j = a >= 1.1;
- j = b <= 1.1;
- j = isunorderedf(a, b);
-
-// no-inf-no-nan-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point option}}
-// no-inf-no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point option}}
+// no-inf-no-nan-warning at +5 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +2{{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = isunorderedf(a, NAN);
-// no-inf-no-nan-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
j = isunorderedf(a, INFINITY);
-// no-inf-no-nan-warning at +6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +5 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +9 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +8 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +7 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +6 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +5 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+//no-inf-no-nan-mix-mode-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
i = std::isunordered(a, NAN);
-// no-inf-no-nan-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
-// no-nan-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +6 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +4 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
+// no-nan-warning at +3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
+//no-inf-no-nan-mix-mode-warning at +2 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options; mix of safe and unsafe math options are used. Check the order of you command line arguments}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
i = std::isunordered(a, INFINITY);
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
double y = i * numeric_limits<double>::infinity();
-// no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-// no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-warning at +3 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+// no-inf-no-nan-mix-mode-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
j = numeric_limits<float>::infinity();
- return 0;
+ // These should NOT warn, since they are not using NaN or infinity.
+ j = a > 1.1;
+ j = b < 1.1;
+ j = a >= 1.1;
+ j = b <= 1.1;
+ j = isunorderedf(a, b);
+
+#ifndef INFINITY
+ j = a;
+#endif
+#ifndef NAN
+ j = b;
+#endif
+#ifdef INFINITY
+ j = a;
+#endif
+#ifdef NAN
+ j = b;
+#endif
+ return 0;
}
More information about the cfe-commits
mailing list