[cfe-commits] r44424 - /cfe/trunk/Sema/SemaChecking.cpp

Ted Kremenek kremenek at apple.com
Wed Nov 28 16:59:04 PST 2007


Author: kremenek
Date: Wed Nov 28 18:59:04 2007
New Revision: 44424

URL: http://llvm.org/viewvc/llvm-project?rev=44424&view=rev
Log:
Enhanced implementation of -Wfloat-equal to check for comparisons against
floating-point literals that are represented exactly by the APFloat in
FloatingLiteral. For such literals, we do not emit a warning since such checks are
often performed in real code to see if a variable has changed from its original
value. This heuristic clearly can lead to false negatives, but the hope is it will
significantly reduce false positives to help make the compiler flag more useful.

Modified:
    cfe/trunk/Sema/SemaChecking.cpp

Modified: cfe/trunk/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaChecking.cpp?rev=44424&r1=44423&r2=44424&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/Sema/SemaChecking.cpp Wed Nov 28 18:59:04 2007
@@ -715,6 +715,24 @@
       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))





More information about the cfe-commits mailing list