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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47649 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/CFG.cpp b/AST/CFG.cpp
index 335d833..431b2e2 100644
--- a/AST/CFG.cpp
+++ b/AST/CFG.cpp
@@ -656,7 +656,7 @@
CFGBlock* BodyBlock = Visit(F->getBody());
if (!BodyBlock)
- BodyBlock = ExitConditionBlock; // can happen for "for (...;...; ) ;"
+ BodyBlock = EntryConditionBlock; // can happen for "for (...;...; ) ;"
else if (Block)
FinishBlock(BodyBlock);
@@ -710,6 +710,7 @@
if (Stmt* C = W->getCond()) {
Block = ExitConditionBlock;
EntryConditionBlock = addStmt(C);
+ assert (Block == EntryConditionBlock);
if (Block) FinishBlock(EntryConditionBlock);
}
@@ -739,7 +740,7 @@
CFGBlock* BodyBlock = Visit(W->getBody());
if (!BodyBlock)
- BodyBlock = ExitConditionBlock; // can happen for "while(...) ;"
+ BodyBlock = EntryConditionBlock; // can happen for "while(...) ;"
else if (Block)
FinishBlock(BodyBlock);
@@ -817,7 +818,7 @@
BodyBlock = Visit(D->getBody());
if (!BodyBlock)
- BodyBlock = ExitConditionBlock; // can happen for "do ; while(...)"
+ BodyBlock = EntryConditionBlock; // can happen for "do ; while(...)"
else if (Block)
FinishBlock(BodyBlock);