Skip to content
Snippets Groups Projects
Commit 540a73bd authored by Erik Pilkington's avatar Erik Pilkington
Browse files

[CodeGen] Fix a crash when constant folding switch statement

Differential revision: https://reviews.llvm.org/D22542

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276350 91177308-0d34-0410-b5e6-96231b3b80d8
parent 5210a748
No related branches found
No related tags found
No related merge requests found
......@@ -1264,6 +1264,14 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
}
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?");
......
......@@ -18,4 +18,13 @@ int main(void) {
return test(5);
}
void other_test() {
switch(0) {
case 0:
do {
default:;
} while(0);
}
}
// CHECK: call i32 (i8*, ...) @_Z6printfPKcz
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment