[cfe-commits] r43453 - /cfe/trunk/Sema/SemaExpr.cpp

Ted Kremenek kremenek at apple.com
Mon Oct 29 10:13:39 PDT 2007


Author: kremenek
Date: Mon Oct 29 12:13:39 2007
New Revision: 43453

URL: http://llvm.org/viewvc/llvm-project?rev=43453&view=rev
Log:
Added some comments.

Moved a dependent predicate in an if statement to be an assertion
within the if statement body.

Modified:
    cfe/trunk/Sema/SemaExpr.cpp

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43453&r1=43452&r2=43453&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Oct 29 12:13:39 2007
@@ -1218,6 +1218,10 @@
   QualType lType = lex->getType();
   QualType rType = rex->getType();
   
+  
+  // For non-floating point types, check for self-comparisons of the form
+  // x == x, x != x, x < x, etc.  These always evaluate to a constant, and
+  // often indicate logic errors in the program.
   if (!lType->isFloatingType()) {
     if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(IgnoreParen(lex)))
       if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(IgnoreParen(rex)))
@@ -1229,7 +1233,12 @@
     if (lType->isRealType() && rType->isRealType())
       return Context.IntTy;
   } else {
-    if (lType->isFloatingType() && rType->isFloatingType()) {
+    // Check for comparisons of floating point operands using != and ==.
+    // Issue a warning if these are no self-comparisons, as they are not likely
+    // to do what the programmer intended.
+    if (lType->isFloatingType()) {
+      assert (rType->isFloatingType());
+      
       // Special case: check for x == x (which is OK).
       bool EmitWarning = true;
       





More information about the cfe-commits mailing list