Index: cfe/trunk/lib/CodeGen/CGStmt.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGStmt.cpp +++ cfe/trunk/lib/CodeGen/CGStmt.cpp @@ -1264,6 +1264,14 @@ } void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) { + // If there is no enclosing switch instance that we're aware of, then this + // default statement can be elided. This situation only happens when we've + // constant-folded the switch. + if (!SwitchInsn) { + EmitStmt(S.getSubStmt()); + return; + } + llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest(); assert(DefaultBlock->empty() && "EmitDefaultStmt: Default block already defined?"); Index: cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp +++ cfe/trunk/test/CodeGenCXX/switch-case-folding-2.cpp @@ -18,4 +18,13 @@ return test(5); } +void other_test() { + switch(0) { + case 0: + do { + default:; + } while(0); + } +} + // CHECK: call i32 (i8*, ...) @_Z6printfPKcz