[cfe-commits] r129679 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/switch-dce.c
Chris Lattner
sabre at nondot.org
Sun Apr 17 16:21:26 PDT 2011
Author: lattner
Date: Sun Apr 17 18:21:26 2011
New Revision: 129679
URL: http://llvm.org/viewvc/llvm-project?rev=129679&view=rev
Log:
Fix a miscompilation I introduced in r129652, thanks for Eli for tracking
it down. we effectively were compile the testcase into:
void test14(int x) {
switch (x) {
case 11: break;
case 42: test14(97); // fallthrough
default: test14(42); break;
which is not the same thing at all. This fixes a miscompilation of
MallocBench/gs seen on the clang-x86_64-linux-fnt buildbot.
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/CodeGen/switch-dce.c
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=129679&r1=129678&r2=129679&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sun Apr 17 18:21:26 2011
@@ -873,7 +873,8 @@
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;
@@ -882,6 +883,13 @@
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;
}
}
Modified: cfe/trunk/test/CodeGen/switch-dce.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/switch-dce.c?rev=129679&r1=129678&r2=129679&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/switch-dce.c (original)
+++ cfe/trunk/test/CodeGen/switch-dce.c Sun Apr 17 18:21:26 2011
@@ -229,3 +229,19 @@
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;
+ }
+}
+
More information about the cfe-commits
mailing list