diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-05-21 20:30:15 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-05-21 20:30:15 +0000 |
commit | 304a9537e116d54d2d9af9fa0b48009aac3b9926 (patch) | |
tree | 21a79b6ae349b21d478d37163e78c0e705a21805 /clang/lib/Analysis/CFG.cpp | |
parent | 27ac429624675306626af028f50cc3bfe172fe7e (diff) | |
download | bcm5719-llvm-304a9537e116d54d2d9af9fa0b48009aac3b9926.tar.gz bcm5719-llvm-304a9537e116d54d2d9af9fa0b48009aac3b9926.zip |
Fix crash in CFG construction for 'break' statements appearing in statement expressions
within the increment code of a for loop.
llvm-svn: 104375
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r-- | clang/lib/Analysis/CFG.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index c7eb53d3613..6f2cb41a6e4 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -985,6 +985,11 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) { } else LoopSuccessor = Succ; + // Save the current value for the break targets. + // All breaks should go to the code following the loop. + SaveAndRestore<CFGBlock*> save_break(BreakTargetBlock); + BreakTargetBlock = LoopSuccessor; + // Because of short-circuit evaluation, the condition of the loop can span // multiple basic blocks. Thus we need the "Entry" and "Exit" blocks that // evaluate the condition. @@ -1032,10 +1037,9 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) { { assert(F->getBody()); - // Save the current values for Block, Succ, and continue and break targets - SaveAndRestore<CFGBlock*> save_Block(Block), save_Succ(Succ), - save_continue(ContinueTargetBlock), - save_break(BreakTargetBlock); + // Save the current values for Block, Succ, and continue targets. + SaveAndRestore<CFGBlock*> save_Block(Block), save_Succ(Succ), + save_continue(ContinueTargetBlock); // Create a new block to contain the (bottom) of the loop body. Block = NULL; @@ -1065,9 +1069,6 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) { // represent the 'loop target' for looping back to the start of the loop. ContinueTargetBlock->setLoopTarget(F); - // All breaks should go to the code following the loop. - BreakTargetBlock = LoopSuccessor; - // Now populate the body block, and in the process create new blocks as we // walk the body of the loop. CFGBlock* BodyBlock = addStmt(F->getBody()); |