[cfe-commits] r126362 - in /cfe/trunk: lib/Analysis/CFG.cpp lib/StaticAnalyzer/Core/Environment.cpp test/Analysis/misc-ps.m

Ted Kremenek kremenek at apple.com
Wed Feb 23 19:09:15 PST 2011


Author: kremenek
Date: Wed Feb 23 21:09:15 2011
New Revision: 126362

URL: http://llvm.org/viewvc/llvm-project?rev=126362&view=rev
Log:
Fix tiny error in CFG construction for BinaryConditionalOperators, making sure the branch always has two successors.  Also teach Environment::getSVal() about OpaqueValueExprs.

This fixes a crash reported in PR9287, and also fixes a false positive involving the value of such ternary
expressions not properly getting propagated.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
    cfe/trunk/test/Analysis/misc-ps.m

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=126362&r1=126361&r2=126362&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Feb 23 21:09:15 2011
@@ -1217,6 +1217,8 @@
       return 0;
     Block = NULL;
   }
+  else
+    LHSBlock = ConfluenceBlock;
 
   // Create the block for the RHS expression.
   Succ = ConfluenceBlock;
@@ -1229,23 +1231,23 @@
 
   // See if this is a known constant.
   const TryResult& KnownVal = tryEvaluateBool(C->getCond());
-  if (LHSBlock)
-    addSuccessor(Block, KnownVal.isFalse() ? NULL : LHSBlock);
+  addSuccessor(Block, KnownVal.isFalse() ? NULL : LHSBlock);
   addSuccessor(Block, KnownVal.isTrue() ? NULL : RHSBlock);
   Block->setTerminator(C);
   Expr *condExpr = C->getCond();
 
-  CFGBlock *result = 0;
-
-  // Run the condition expression if it's not trivially expressed in
-  // terms of the opaque value (or if there is no opaque value).
-  if (condExpr != opaqueValue) result = addStmt(condExpr);
-
-  // Before that, run the common subexpression if there was one.
-  // At least one of this or the above will be run.
-  if (opaqueValue) result = addStmt(BCO->getCommon());
-
-  return result;
+  if (opaqueValue) {
+    // Run the condition expression if it's not trivially expressed in
+    // terms of the opaque value (or if there is no opaque value).
+    if (condExpr != opaqueValue)
+      addStmt(condExpr);
+
+    // Before that, run the common subexpression if there was one.
+    // At least one of this or the above will be run.
+    return addStmt(BCO->getCommon());
+  }
+  
+  return addStmt(condExpr);
 }
 
 CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=126362&r1=126361&r2=126362&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Wed Feb 23 21:09:15 2011
@@ -32,6 +32,11 @@
     switch (E->getStmtClass()) {
       case Stmt::AddrLabelExprClass:
         return svalBuilder.makeLoc(cast<AddrLabelExpr>(E));
+      case Stmt::OpaqueValueExprClass: {
+        const OpaqueValueExpr *ope = cast<OpaqueValueExpr>(E);
+        E = ope->getSourceExpr();
+        continue;        
+      }        
       case Stmt::ParenExprClass:
         // ParenExprs are no-ops.
         E = cast<ParenExpr>(E)->getSubExpr();

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=126362&r1=126361&r2=126362&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Wed Feb 23 21:09:15 2011
@@ -1246,3 +1246,26 @@
        ++i) {}
 }
 
+// Test evaluation of GNU-style ?:.
+int pr9287(int type) { return type ? : 0; } // no-warning
+
+void pr9287_b(int type, int *p) { 
+  int x = type ? : 0;
+  if (x) {
+    p = 0;
+  }
+  if (type) {
+    *p = 0xDEADBEEF; // expected-warning {{null pointer}}
+  }
+}
+
+void pr9287_c(int type, int *p) { 
+  int x = type ? : 0;
+  if (x) {
+    p = 0;
+  }
+  if (!type) {
+    *p = 0xDEADBEEF; // no-warning
+  }
+}
+





More information about the cfe-commits mailing list