[cfe-commits] r117436 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/misc-ps-region-store.m

Zhongxing Xu xuzhongxing at gmail.com
Tue Oct 26 20:23:10 PDT 2010


Author: zhongxingxu
Date: Tue Oct 26 22:23:10 2010
New Revision: 117436

URL: http://llvm.org/viewvc/llvm-project?rev=117436&view=rev
Log:
If visiting RHS causes us to finish 'Block', e.g. the RHS is a StmtExpr
containing a DoStmt, and the LHS doesn't create a new block, then we should
return RBlock.  Otherwise we'll incorrectly return NULL.

Also relax an assertion in VisitWhileStmt(). Reset 'Block' when it is finished.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.m

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=117436&r1=117435&r2=117436&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Oct 26 22:23:10 2010
@@ -935,8 +935,12 @@
     AppendStmt(Block, B, asc);
   }
 
-  Visit(B->getRHS());
-  return Visit(B->getLHS());
+  CFGBlock *RBlock = Visit(B->getRHS());
+  CFGBlock *LBlock = Visit(B->getLHS());
+  // If visiting RHS causes us to finish 'Block', e.g. the RHS is a StmtExpr
+  // containing a DoStmt, and the LHS doesn't create a new block, then we should
+  // return RBlock.  Otherwise we'll incorrectly return NULL.
+  return (LBlock ? LBlock : RBlock);
 }
 
 CFGBlock *CFGBuilder::VisitBlockExpr(BlockExpr *E, AddStmtChoice asc) {
@@ -1736,7 +1740,8 @@
   if (Stmt* C = W->getCond()) {
     Block = ExitConditionBlock;
     EntryConditionBlock = addStmt(C);
-    assert(Block == EntryConditionBlock);
+    // The condition might finish the current 'Block'.
+    Block = EntryConditionBlock;
 
     // If this block contains a condition variable, add both the condition
     // variable and initializer to the CFG.

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=117436&r1=117435&r2=117436&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Tue Oct 26 22:23:10 2010
@@ -1157,6 +1157,12 @@
     }
 }
 
+// Don't crash when building the CFG.
+void do_not_crash(int x) {
+  while (x - ({do {} while (0); x; })) {
+  }
+}
+
 // <rdar://problem/8424269> - Handle looking at the size of a VLA in
 // ArrayBoundChecker.  Nothing intelligent (yet); just don't crash.
 typedef struct RDar8424269_A {





More information about the cfe-commits mailing list