@@ -2201,8 +2201,9 @@ CFGBlock* CFGBuilder::VisitSwitchStmt(SwitchStmt* Terminator) {
2201
2201
// Determine if the switch condition can be explicitly evaluated.
2202
2202
assert (Terminator->getCond () && " switch condition must be non-NULL" );
2203
2203
Expr::EvalResult result;
2204
- tryEvaluate (Terminator->getCond (), result);
2205
- SaveAndRestore<Expr::EvalResult*> save_switchCond (switchCond, &result);
2204
+ bool b = tryEvaluate (Terminator->getCond (), result);
2205
+ SaveAndRestore<Expr::EvalResult*> save_switchCond (switchCond,
2206
+ b ? &result : 0 );
2206
2207
2207
2208
// If body is not a compound statement create implicit scope
2208
2209
// and add destructors.
@@ -2239,18 +2240,21 @@ CFGBlock* CFGBuilder::VisitSwitchStmt(SwitchStmt* Terminator) {
2239
2240
}
2240
2241
2241
2242
static bool shouldAddCase (bool &switchExclusivelyCovered,
2242
- const Expr::EvalResult & switchCond,
2243
+ const Expr::EvalResult * switchCond,
2243
2244
const CaseStmt *CS,
2244
2245
ASTContext &Ctx) {
2246
+ if (!switchCond)
2247
+ return true ;
2248
+
2245
2249
bool addCase = false ;
2246
2250
2247
2251
if (!switchExclusivelyCovered) {
2248
- if (switchCond. Val .isInt ()) {
2252
+ if (switchCond-> Val .isInt ()) {
2249
2253
// Evaluate the LHS of the case value.
2250
2254
Expr::EvalResult V1;
2251
2255
CS->getLHS ()->Evaluate (V1, Ctx);
2252
2256
assert (V1.Val .isInt ());
2253
- const llvm::APSInt &condInt = switchCond. Val .getInt ();
2257
+ const llvm::APSInt &condInt = switchCond-> Val .getInt ();
2254
2258
const llvm::APSInt &lhsInt = V1.Val .getInt ();
2255
2259
2256
2260
if (condInt == lhsInt) {
@@ -2280,7 +2284,6 @@ CFGBlock* CFGBuilder::VisitCaseStmt(CaseStmt* CS) {
2280
2284
// CaseStmts are essentially labels, so they are the first statement in a
2281
2285
// block.
2282
2286
CFGBlock *TopBlock = 0 , *LastBlock = 0 ;
2283
- assert (switchCond);
2284
2287
2285
2288
if (Stmt *Sub = CS->getSubStmt ()) {
2286
2289
// For deeply nested chains of CaseStmts, instead of doing a recursion
@@ -2296,7 +2299,7 @@ CFGBlock* CFGBuilder::VisitCaseStmt(CaseStmt* CS) {
2296
2299
TopBlock = currentBlock;
2297
2300
2298
2301
addSuccessor (SwitchTerminatedBlock,
2299
- shouldAddCase (switchExclusivelyCovered, * switchCond,
2302
+ shouldAddCase (switchExclusivelyCovered, switchCond,
2300
2303
CS, *Context)
2301
2304
? currentBlock : 0 );
2302
2305
@@ -2323,7 +2326,7 @@ CFGBlock* CFGBuilder::VisitCaseStmt(CaseStmt* CS) {
2323
2326
// statement.
2324
2327
assert (SwitchTerminatedBlock);
2325
2328
addSuccessor (SwitchTerminatedBlock,
2326
- shouldAddCase (switchExclusivelyCovered, * switchCond,
2329
+ shouldAddCase (switchExclusivelyCovered, switchCond,
2327
2330
CS, *Context)
2328
2331
? CaseBlock : 0 );
2329
2332
0 commit comments