]> granicus.if.org Git - clang/commitdiff
Fix static analyzer regression when emitting undefined value warnings
authorTed Kremenek <kremenek@apple.com>
Tue, 15 Sep 2009 17:43:54 +0000 (17:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 15 Sep 2009 17:43:54 +0000 (17:43 +0000)
with binary operators.  The result of a binary operator may be
undefined even if its operands are well-defined.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81874 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngineInternalChecks.cpp

index fcc2db467fec1050f2d2c39607e75319688a2fd8..21f146520479aa17f5fa2391b868f8a0d40c6a6f 100644 (file)
@@ -222,25 +222,32 @@ public:
         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,