[cfe-commits] r81874 - /cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp

Ted Kremenek kremenek at apple.com
Tue Sep 15 10:43:54 PDT 2009


Author: kremenek
Date: Tue Sep 15 12:43:54 2009
New Revision: 81874

URL: http://llvm.org/viewvc/llvm-project?rev=81874&view=rev
Log:
Fix static analyzer regression when emitting undefined value warnings
with binary operators.  The result of a binary operator may be
undefined even if its operands are well-defined.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp

Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=81874&r1=81873&r2=81874&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Tue Sep 15 12:43:54 2009
@@ -222,25 +222,32 @@
         llvm::SmallString<256> sbuf;
         llvm::raw_svector_ostream OS(sbuf);
         const GRState *ST = N->getState();
-        const Expr *Ex;
+        const Expr *Ex = NULL; 
 
         if (ST->getSVal(B->getLHS()).isUndef()) {
           Ex = B->getLHS()->IgnoreParenCasts();
           OS << "The left operand of the '";
         }
-        else {
-          assert(ST->getSVal(B->getRHS()).isUndef());
+        else if (ST->getSVal(B->getRHS()).isUndef()) {
           Ex = B->getRHS()->IgnoreParenCasts();
           OS << "The right operand of the '";
         }
-                
-        OS << BinaryOperator::getOpcodeStr(B->getOpcode())
-           << "' expression is an undefined "
-              "or otherwise garbage value";
-        
+      
+        if (Ex) {                  
+          OS << BinaryOperator::getOpcodeStr(B->getOpcode())
+             << "' expression is an undefined "
+                "or otherwise garbage value";
+        }          
+        else {
+          // We KNOW that the result was undefined.
+          OS << "The result of the '"
+             << BinaryOperator::getOpcodeStr(B->getOpcode())
+             << "' expression is undefined";
+        }
+      
         // FIXME: Use StringRefs to pass string information.
         report = new BuiltinBugReport(*this, OS.str().str().c_str(), N);
-        report->addRange(Ex->getSourceRange());
+        if (Ex) report->addRange(Ex->getSourceRange());
       }
       else {
         report = new BuiltinBugReport(*this, 





More information about the cfe-commits mailing list