diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-03-22 05:57:43 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-03-22 05:57:43 +0000 |
commit | 213d05304e4416eabf66f13d36ca98a675f30e44 (patch) | |
tree | edc5890f404b2fceb12f904cff62b8ea1230d7a1 /clang/lib/Analysis/CFG.cpp | |
parent | e26dafeb79f5d5b5be6a9e0ca227e14dac57d34a (diff) | |
download | bcm5719-llvm-213d05304e4416eabf66f13d36ca98a675f30e44.tar.gz bcm5719-llvm-213d05304e4416eabf66f13d36ca98a675f30e44.zip |
Fix broken CFG when an initializer is a statement expression that starts with a while loop (PR 12325).
llvm-svn: 153242
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r-- | clang/lib/Analysis/CFG.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 24ca9588271..d0ccef68901 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1464,14 +1464,24 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { autoCreateBlock(); appendStmt(Block, DS); + + // Keep track of the last non-null block, as 'Block' can be nulled out + // if the initializer expression is something like a 'while' in a + // statement-expression. + CFGBlock *LastBlock = Block; if (Init) { - if (HasTemporaries) + if (HasTemporaries) { // For expression with temporaries go directly to subexpression to omit // generating destructors for the second time. - Visit(cast<ExprWithCleanups>(Init)->getSubExpr()); - else - Visit(Init); + ExprWithCleanups *EC = cast<ExprWithCleanups>(Init); + if (CFGBlock *newBlock = Visit(EC->getSubExpr())) + LastBlock = newBlock; + } + else { + if (CFGBlock *newBlock = Visit(Init)) + LastBlock = newBlock; + } } // If the type of VD is a VLA, then we must process its size expressions. @@ -1483,7 +1493,7 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { if (ScopePos && VD == *ScopePos) ++ScopePos; - return Block; + return Block ? Block : LastBlock; } CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { |