Skip to content

Commit 39321aa

Browse files
committed
Fixed CFG construction bug that occurred when a condition for a loop spanned
multiple basic blocks (which can happen when they contain '&&', '||', '?'). The bug was that the loop backedge when to the last block in the loop condition, not the first. llvm-svn: 47649
1 parent ae2b6fb commit 39321aa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clang/AST/CFG.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) {
656656
CFGBlock* BodyBlock = Visit(F->getBody());
657657

658658
if (!BodyBlock)
659-
BodyBlock = ExitConditionBlock; // can happen for "for (...;...; ) ;"
659+
BodyBlock = EntryConditionBlock; // can happen for "for (...;...; ) ;"
660660
else if (Block)
661661
FinishBlock(BodyBlock);
662662

@@ -710,6 +710,7 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
710710
if (Stmt* C = W->getCond()) {
711711
Block = ExitConditionBlock;
712712
EntryConditionBlock = addStmt(C);
713+
assert (Block == EntryConditionBlock);
713714
if (Block) FinishBlock(EntryConditionBlock);
714715
}
715716

@@ -739,7 +740,7 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
739740
CFGBlock* BodyBlock = Visit(W->getBody());
740741

741742
if (!BodyBlock)
742-
BodyBlock = ExitConditionBlock; // can happen for "while(...) ;"
743+
BodyBlock = EntryConditionBlock; // can happen for "while(...) ;"
743744
else if (Block)
744745
FinishBlock(BodyBlock);
745746

@@ -817,7 +818,7 @@ CFGBlock* CFGBuilder::VisitDoStmt(DoStmt* D) {
817818
BodyBlock = Visit(D->getBody());
818819

819820
if (!BodyBlock)
820-
BodyBlock = ExitConditionBlock; // can happen for "do ; while(...)"
821+
BodyBlock = EntryConditionBlock; // can happen for "do ; while(...)"
821822
else if (Block)
822823
FinishBlock(BodyBlock);
823824

0 commit comments

Comments
 (0)