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