[cfe-commits] r115256 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/auto-obj-dtors-cfg-output.cpp

Marcin Swiderski marcin.sfider at gmail.com
Thu Sep 30 17:52:17 PDT 2010


Author: sfider
Date: Thu Sep 30 19:52:17 2010
New Revision: 115256

URL: http://llvm.org/viewvc/llvm-project?rev=115256&view=rev
Log:
Added generating CFGAutomaticObjDtors for condition variable and implicit scopes in if statement.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=115256&r1=115255&r2=115256&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Thu Sep 30 19:52:17 2010
@@ -1136,6 +1136,18 @@
   // middle of a block, we stop processing that block.  That block is then the
   // implicit successor for the "then" and "else" clauses.
 
+  // Save local scope position because in case of condition variable ScopePos
+  // won't be restored when traversing AST.
+  SaveAndRestore<LocalScope::const_iterator> save_scope_pos(ScopePos);
+
+  // Create local scope for possible condition variable.
+  // Store scope position. Add implicit destructor.
+  if (VarDecl* VD = I->getConditionVariable()) {
+    LocalScope::const_iterator BeginScopePos = ScopePos;
+    addLocalScopeForVarDecl(VD);
+    addAutomaticObjDtors(ScopePos, BeginScopePos, I);
+  }
+
   // The block we were proccessing is now finished.  Make it the successor
   // block.
   if (Block) {
@@ -1153,6 +1165,12 @@
     // NULL out Block so that the recursive call to Visit will
     // create a new basic block.
     Block = NULL;
+
+    // If branch is not a compound statement create implicit scope
+    // and add destructors.
+    if (!isa<CompoundStmt>(Else))
+      addLocalScopeAndDtors(Else);
+
     ElseBlock = addStmt(Else);
 
     if (!ElseBlock) // Can occur when the Else body has all NullStmts.
@@ -1170,6 +1188,12 @@
     assert(Then);
     SaveAndRestore<CFGBlock*> sv(Succ);
     Block = NULL;
+
+    // If branch is not a compound statement create implicit scope
+    // and add destructors.
+    if (!isa<CompoundStmt>(Then))
+      addLocalScopeAndDtors(Then);
+
     ThenBlock = addStmt(Then);
 
     if (!ThenBlock) {

Modified: cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp?rev=115256&r1=115255&r2=115256&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp Thu Sep 30 19:52:17 2010
@@ -44,6 +44,27 @@
   A c;
 }
 
+void test_if_implicit_scope() {
+  A a;
+  if (A b = a)
+    A c;
+  else A c;
+}
+
+void test_if_jumps() {
+  A a;
+  if (A b = a) {
+    A c;
+    if (UV) return;
+    A d;
+  } else {
+    A c;
+    if (UV) return;
+    A d;
+  }
+  A e;
+}
+
 // CHECK:  [ B2 (ENTRY) ]
 // CHECK:     Predecessors (0):
 // CHECK:     Successors (1): B1
@@ -149,3 +170,98 @@
 // CHECK:  [ B0 (EXIT) ]
 // CHECK:     Predecessors (1): B1
 // CHECK:     Successors (0):
+// CHECK:  [ B5 (ENTRY) ]
+// CHECK:     Predecessors (0):
+// CHECK:     Successors (1): B4
+// CHECK:  [ B1 ]
+// CHECK:       1: [B4.3].~A() (Implicit destructor)
+// CHECK:       2: [B4.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (2): B2 B3
+// CHECK:     Successors (1): B0
+// CHECK:  [ B2 ]
+// CHECK:       1: A c;
+// CHECK:       2: [B2.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B4
+// CHECK:     Successors (1): B1
+// CHECK:  [ B3 ]
+// CHECK:       1: A c;
+// CHECK:       2: [B3.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B4
+// CHECK:     Successors (1): B1
+// CHECK:  [ B4 ]
+// CHECK:       1: A a;
+// CHECK:       2: a
+// CHECK:       3: if ([B4.5])
+// CHECK: [B3.1]else
+// CHECK: [B2.1]      4: b.operator int()
+// CHECK:       5: [B4.4]
+// CHECK:       T: if [B4.5]
+// CHECK:     Predecessors (1): B5
+// CHECK:     Successors (2): B3 B2
+// CHECK:  [ B0 (EXIT) ]
+// CHECK:     Predecessors (1): B1
+// CHECK:     Successors (0):
+// CHECK:  [ B9 (ENTRY) ]
+// CHECK:     Predecessors (0):
+// CHECK:     Successors (1): B8
+// CHECK:  [ B1 ]
+// CHECK:       1: [B8.3].~A() (Implicit destructor)
+// CHECK:       2: A e;
+// CHECK:       3: [B1.2].~A() (Implicit destructor)
+// CHECK:       4: [B8.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (2): B2 B5
+// CHECK:     Successors (1): B0
+// CHECK:  [ B2 ]
+// CHECK:       1: A d;
+// CHECK:       2: [B2.1].~A() (Implicit destructor)
+// CHECK:       3: [B4.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B4
+// CHECK:     Successors (1): B1
+// CHECK:  [ B3 ]
+// CHECK:       1: return;
+// CHECK:       2: [B4.1].~A() (Implicit destructor)
+// CHECK:       3: [B8.3].~A() (Implicit destructor)
+// CHECK:       4: [B8.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B4
+// CHECK:     Successors (1): B0
+// CHECK:  [ B4 ]
+// CHECK:       1: A c;
+// CHECK:       2: UV
+// CHECK:       T: if [B4.2]
+// CHECK:     Predecessors (1): B8
+// CHECK:     Successors (2): B3 B2
+// CHECK:  [ B5 ]
+// CHECK:       1: A d;
+// CHECK:       2: [B5.1].~A() (Implicit destructor)
+// CHECK:       3: [B7.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B7
+// CHECK:     Successors (1): B1
+// CHECK:  [ B6 ]
+// CHECK:       1: return;
+// CHECK:       2: [B7.1].~A() (Implicit destructor)
+// CHECK:       3: [B8.3].~A() (Implicit destructor)
+// CHECK:       4: [B8.1].~A() (Implicit destructor)
+// CHECK:     Predecessors (1): B7
+// CHECK:     Successors (1): B0
+// CHECK:  [ B7 ]
+// CHECK:       1: A c;
+// CHECK:       2: UV
+// CHECK:       T: if [B7.2]
+// CHECK:     Predecessors (1): B8
+// CHECK:     Successors (2): B6 B5
+// CHECK:  [ B8 ]
+// CHECK:       1: A a;
+// CHECK:       2: a
+// CHECK:       3: if ([B8.5]) {
+// CHECK: [B7.1]    if ([B7.2])
+// CHECK: [B6.1][B5.1]} else {
+// CHECK: [B4.1]    if ([B4.2])
+// CHECK: [B3.1][B2.1]}
+// CHECK:       4: b.operator int()
+// CHECK:       5: [B8.4]
+// CHECK:       T: if [B8.5]
+// CHECK:     Predecessors (1): B9
+// CHECK:     Successors (2): B7 B4
+// CHECK:  [ B0 (EXIT) ]
+// CHECK:     Predecessors (3): B1 B3 B6
+// CHECK:     Successors (0):





More information about the cfe-commits mailing list