return;
}
- // If the body of the case is just a 'break', try to not emit an empty block.
+ // If the body of the case is just a 'break', and if there was no fallthrough,
+ // try to not emit an empty block.
if (isa<BreakStmt>(S.getSubStmt())) {
JumpDest Block = BreakContinueStack.back().BreakBlock;
llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext());
SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), CaseVal),
Block.getBlock());
+
+ // If there was a fallthrough into this case, make sure to redirect it to
+ // the end of the switch as well.
+ if (Builder.GetInsertBlock()) {
+ Builder.CreateBr(Block.getBlock());
+ Builder.ClearInsertionPoint();
+ }
return;
}
}
default: test13(42); break;
}
}
+
+
+// Verify that case 42 only calls test14 once.
+// CHECK: @test14
+// CHECK: call void @test14(i32 97)
+// CHECK-NEXT: br label [[EPILOG2:%[0-9.a-z]+]]
+// CHECK: call void @test14(i32 42)
+// CHECK-NEXT: br label [[EPILOG2]]
+void test14(int x) {
+ switch (x) {
+ case 42: test14(97); // fallthrough
+ case 11: break;
+ default: test14(42); break;
+ }
+}
+