/// 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());
}
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);
return calledFun(); // expected-warning {{will never be executed}}
}
+enum X { A, B, C };
+
+int covered_switch(enum X x) {
+ switch (x) {
+ case A: return 1;
+ case B: return 2;
+ case C: return 3;
+ }
+ return 4; // no-warning
+}
+
// Test unreachable code depending on configuration values
#define CONFIG_CONSTANT 1
int test_config_constant(int x) {