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

Ted Kremenek kremenek at apple.com
Wed Dec 23 17:34:10 PST 2009


Author: kremenek
Date: Wed Dec 23 19:34:10 2009
New Revision: 92111

URL: http://llvm.org/viewvc/llvm-project?rev=92111&view=rev
Log:
CFG tweak: in a WhileStmt, the condition variable initializer is evaluated every time the condition is checked.

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

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Dec 23 19:34:10 2009
@@ -1130,6 +1130,18 @@
     Block = ExitConditionBlock;
     EntryConditionBlock = addStmt(C);
     assert(Block == EntryConditionBlock);
+    
+    // If this block contains a condition variable, add both the condition
+    // variable and initializer to the CFG.
+    if (VarDecl *VD = W->getConditionVariable()) {
+      if (Expr *Init = VD->getInit()) {
+        autoCreateBlock();
+        AppendStmt(Block, W, AddStmtChoice::AlwaysAdd);
+        EntryConditionBlock = addStmt(Init);
+        assert(Block == EntryConditionBlock);
+      }
+    }
+
     if (Block) {
       if (!FinishBlock(EntryConditionBlock))
         return 0;
@@ -1188,21 +1200,8 @@
   // to this block.  NULL out Block to force lazy creation of another block.
   Block = NULL;
 
-  // Set Succ to be the condition block, which is the dominating block
-  // for the loop.
+  // Return the condition block, which is the dominating block for the loop.
   Succ = EntryConditionBlock;
-  
-  // Finally, if the WhileStmt contains a condition variable, add both the 
-  // WhileStmt and the condition variable initialization to the CFG.
-  if (VarDecl *VD = W->getConditionVariable()) {
-    if (Expr *Init = VD->getInit()) {
-      autoCreateBlock();
-      AppendStmt(Block, W, AddStmtChoice::AlwaysAdd);
-      Succ = addStmt(Init);
-      return Succ;
-    }
-  }
-  
   return EntryConditionBlock;
 }
 

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.cpp?rev=92111&r1=92110&r2=92111&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.cpp (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.cpp Wed Dec 23 19:34:10 2009
@@ -61,16 +61,17 @@
 }
 
 int test_init_in_condition_while() {
-  int y = 1;
-  while (int x = test_init_in_condition_aux()) { // no-warning
-    if (!x) {
-      y = 0;
+  int z = 0;
+  while (int x = ++z) { // no-warning
+    if (x == 2)
       break;
-    }
-  }  
-  if (!y) {
-    int *p = 0;
-    *p = 0xDEADBEEF; // no-warning
   }
+  
+  if (z == 2)
+    return 0;
+  
+  int *p = 0;
+  *p = 0xDEADBEEF; // no-warning
   return 0;
 }
+





More information about the cfe-commits mailing list