r227627 - SEH: Don't jump to an unreachable continuation block
Reid Kleckner
reid at kleckner.net
Fri Jan 30 14:16:45 PST 2015
Author: rnk
Date: Fri Jan 30 16:16:45 2015
New Revision: 227627
URL: http://llvm.org/viewvc/llvm-project?rev=227627&view=rev
Log:
SEH: Don't jump to an unreachable continuation block
If both the __try and __except blocks do not return, we want to delete
the continuation block as unreachable instead.
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/test/CodeGen/exceptions-seh.c
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=227627&r1=227626&r2=227627&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Fri Jan 30 16:16:45 2015
@@ -1899,7 +1899,8 @@ void CodeGenFunction::ExitSEHTryStmt(con
// Emit the __except body.
EmitStmt(Except->getBlock());
- Builder.CreateBr(ContBB);
+ if (HaveInsertPoint())
+ Builder.CreateBr(ContBB);
EmitBlock(ContBB);
}
Modified: cfe/trunk/test/CodeGen/exceptions-seh.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh.c?rev=227627&r1=227626&r2=227627&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exceptions-seh.c (original)
+++ cfe/trunk/test/CodeGen/exceptions-seh.c Fri Jan 30 16:16:45 2015
@@ -38,7 +38,7 @@ int safe_div(int numerator, int denomina
void j(void);
// FIXME: Implement local variable captures in filter expressions.
-int filter_expr_capture() {
+int filter_expr_capture(void) {
int r = 42;
__try {
j();
@@ -65,7 +65,7 @@ int filter_expr_capture() {
// FIXMECHECK: store i32 -1, i32* %{{.*}}
// CHECK: ret i32 -1
-int nested_try() {
+int nested_try(void) {
int r = 42;
__try {
__try {
@@ -121,7 +121,7 @@ int nested_try() {
// FIXME: This lowering of __finally can't actually work, it will have to
// change.
static unsigned g = 0;
-void basic_finally() {
+void basic_finally(void) {
++g;
__try {
j();
@@ -150,3 +150,27 @@ void basic_finally() {
// CHECK: add i32 %{{.*}}, -1
// CHECK: store i32 %{{.*}}, i32* @g
// CHECK: resume
+
+int returns_int(void);
+int except_return(void) {
+ __try {
+ return returns_int();
+ } __except(1) {
+ return 42;
+ }
+}
+// CHECK-LABEL: define i32 @except_return()
+// CHECK: %[[tmp:[^ ]*]] = invoke i32 @returns_int()
+// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
+//
+// CHECK: [[cont]]
+// CHECK: store i32 %[[tmp]], i32* %[[rv:[^ ]*]]
+// CHECK: br label %[[retbb:[^ ]*]]
+//
+// CHECK: [[lpad]]
+// CHECK: store i32 42, i32* %[[rv]]
+// CHECK: br label %[[retbb]]
+//
+// CHECK: [[retbb]]
+// CHECK: %[[r:[^ ]*]] = load i32* %[[rv]]
+// CHECK: ret i32 %[[r]]
More information about the cfe-commits
mailing list