[-Wunreachable-code] Refine treating all branches of 'switch' as reachable, which includes those with all cases covered but with no 'default:'.
llvm-svn: 203094
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 79e8d8c..45930c0 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -457,6 +457,10 @@
/// Returns true if we should always explore all successors of a block.
static bool shouldTreatSuccessorsAsReachable(const CFGBlock *B) {
+ if (const Stmt *Term = B->getTerminator())
+ if (isa<SwitchStmt>(Term))
+ return true;
+
return isConfigurationValue(B->getTerminatorCondition());
}
@@ -500,24 +504,6 @@
B = UB;
break;
}
-
- // For switch statements, treat all cases as being reachable.
- // There are many cases where a switch can contain values that
- // are not in an enumeration but they are still reachable because
- // other values are possible.
- //
- // Note that this is quite conservative. If one saw:
- //
- // switch (1) {
- // case 2: ...
- //
- // we should be able to say that 'case 2' is unreachable. To do
- // this we can either put more heuristics here, or possibly retain
- // that information in the CFG itself.
- //
- const Stmt *Label = UB->getLabel();
- if (Label && isa<SwitchCase>(Label))
- B = UB;
}
while (false);