[StaticAnalyzer] Fix UnreachableCode false positives.

When there is 'do { } while (0);' in the code the ExplodedGraph and UnoptimizedCFG did not match.

Differential Revision: https://reviews.llvm.org/D24759

llvm-svn: 283095
This commit is contained in:
Daniel Marjamaki 2016-10-03 08:28:51 +00:00
parent c87d2a613e
commit 042a3c5a2d
2 changed files with 20 additions and 11 deletions

View File

@ -2983,20 +2983,19 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) {
return nullptr;
}
if (!KnownVal.isFalse()) {
// Add an intermediate block between the BodyBlock and the
// ExitConditionBlock to represent the "loop back" transition. Create an
// empty block to represent the transition block for looping back to the
// head of the loop.
// FIXME: Can we do this more efficiently without adding another block?
Block = nullptr;
Succ = BodyBlock;
CFGBlock *LoopBackBlock = createBlock();
LoopBackBlock->setLoopTarget(D);
// Add an intermediate block between the BodyBlock and the
// ExitConditionBlock to represent the "loop back" transition. Create an
// empty block to represent the transition block for looping back to the
// head of the loop.
// FIXME: Can we do this more efficiently without adding another block?
Block = nullptr;
Succ = BodyBlock;
CFGBlock *LoopBackBlock = createBlock();
LoopBackBlock->setLoopTarget(D);
if (!KnownVal.isFalse())
// Add the loop body entry as a successor to the condition.
addSuccessor(ExitConditionBlock, LoopBackBlock);
}
else
addSuccessor(ExitConditionBlock, nullptr);
}

View File

@ -173,3 +173,13 @@ void varDecl(int X) {
}
}
// Ensure that ExplodedGraph and unoptimized CFG match.
void test12(int x) {
switch (x) {
case 1:
break; // not unreachable
case 2:
do { } while (0);
break;
}
}