Teach CFGBuilder that the 'default' branch of a switch statement is dead if all enum values in a switch conditioned are handled.

llvm-svn: 127727
This commit is contained in:
Ted Kremenek
2011-03-16 04:32:01 +00:00
parent 76e68ea916
commit 35c70f64db
2 changed files with 17 additions and 2 deletions

View File

@@ -2249,9 +2249,11 @@ CFGBlock* CFGBuilder::VisitSwitchStmt(SwitchStmt* Terminator) {
}
// If we have no "default:" case, the default transition is to the code
// following the switch body.
// following the switch body. Moreover, take into account if all the
// cases of a switch are covered (e.g., switching on an enum value).
addSuccessor(SwitchTerminatedBlock,
switchExclusivelyCovered ? 0 : DefaultCaseBlock);
switchExclusivelyCovered || Terminator->isAllEnumCasesCovered()
? 0 : DefaultCaseBlock);
// Add the terminator and condition in the switch block.
SwitchTerminatedBlock->setTerminator(Terminator);