aboutsummaryrefslogtreecommitdiff
path: root/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Sema/SemaChecking.cpp')
-rw-r--r--Sema/SemaChecking.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Sema/SemaChecking.cpp b/Sema/SemaChecking.cpp
index cb22f03a31..20f0b81b43 100644
--- a/Sema/SemaChecking.cpp
+++ b/Sema/SemaChecking.cpp
@@ -715,6 +715,24 @@ void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) {
if (DRL->getDecl() == DRR->getDecl())
EmitWarning = false;
+
+ // Special case: check for comparisons against literals that can be exactly
+ // represented by APFloat. In such cases, do not emit a warning. This
+ // is a heuristic: often comparison against such literals are used to
+ // detect if a value in a variable has not changed. This clearly can
+ // lead to false negatives.
+ if (EmitWarning) {
+ if (FloatingLiteral* FLL = dyn_cast<FloatingLiteral>(LeftExprSansParen)) {
+ if (FLL->isExact())
+ EmitWarning = false;
+ }
+ else
+ if (FloatingLiteral* FLR = dyn_cast<FloatingLiteral>(RightExprSansParen)){
+ if (FLR->isExact())
+ EmitWarning = false;
+ }
+ }
+
// Check for comparisons with builtin types.
if (EmitWarning)
if (CallExpr* CL = dyn_cast<CallExpr>(LeftExprSansParen))