aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/CFG.cpp
diff options
context:
space:
mode:
authorMarcin Swiderski <marcin.sfider@gmail.com>2010-10-01 01:14:17 +0000
committerMarcin Swiderski <marcin.sfider@gmail.com>2010-10-01 01:14:17 +0000
commit05adedcb5e199e377e35f576288caf5ceed40136 (patch)
treebaa4c46e6fb0b4e952a83f6fc3d6c0fbd590fec1 /lib/Analysis/CFG.cpp
parent85e5191934143edfa9fed582149d8f85c99c753f (diff)
Added generating CFGAutomaticObjDtors for condition variable and implicit scopes in while and do statements.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115262 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CFG.cpp')
-rw-r--r--lib/Analysis/CFG.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp
index fd8b009aba..212f3ea7f3 100644
--- a/lib/Analysis/CFG.cpp
+++ b/lib/Analysis/CFG.cpp
@@ -1584,7 +1584,17 @@ CFGBlock* CFGBuilder::VisitObjCAtTryStmt(ObjCAtTryStmt* S) {
CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
CFGBlock* LoopSuccessor = NULL;
+ // 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 for continue statement.
LocalScope::const_iterator LoopBeginScopePos = ScopePos;
+ if (VarDecl* VD = W->getConditionVariable()) {
+ addLocalScopeForVarDecl(VD);
+ addAutomaticObjDtors(ScopePos, LoopBeginScopePos, W);
+ }
// "while" is a control-flow statement. Thus we stop processing the current
// block.
@@ -1654,11 +1664,19 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
ContinueJumpTarget = JumpTarget(Succ, LoopBeginScopePos);
// All breaks should go to the code following the loop.
- BreakJumpTarget = JumpTarget(LoopSuccessor, LoopBeginScopePos);
+ BreakJumpTarget = JumpTarget(LoopSuccessor, ScopePos);
// NULL out Block to force lazy instantiation of blocks for the body.
Block = NULL;
+ // Loop body should end with destructor of Condition variable (if any).
+ addAutomaticObjDtors(ScopePos, LoopBeginScopePos, W);
+
+ // If body is not a compound statement create implicit scope
+ // and add destructors.
+ if (!isa<CompoundStmt>(W->getBody()))
+ addLocalScopeAndDtors(W->getBody());
+
// Create the body. The returned block is the entry to the loop body.
CFGBlock* BodyBlock = addStmt(W->getBody());
@@ -1789,6 +1807,11 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt* D) {
// NULL out Block to force lazy instantiation of blocks for the body.
Block = NULL;
+ // If body is not a compound statement create implicit scope
+ // and add destructors.
+ if (!isa<CompoundStmt>(D->getBody()))
+ addLocalScopeAndDtors(D->getBody());
+
// Create the body. The returned block is the entry to the loop body.
BodyBlock = addStmt(D->getBody());