diff options
Diffstat (limited to 'test/CodeGen/exceptions-seh.c')
-rw-r--r-- | test/CodeGen/exceptions-seh.c | 181 |
1 files changed, 170 insertions, 11 deletions
diff --git a/test/CodeGen/exceptions-seh.c b/test/CodeGen/exceptions-seh.c index 0a82e379b2cc..d8135e805c6b 100644 --- a/test/CodeGen/exceptions-seh.c +++ b/test/CodeGen/exceptions-seh.c @@ -1,19 +1,178 @@ -// RUN: not %clang_cc1 -triple i686-pc-win32 -fexceptions -fms-extensions -emit-llvm -o - %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s -// This is a codegen test because we only emit the diagnostic when we start -// generating code. +void try_body(int numerator, int denominator, int *myres) { + *myres = numerator / denominator; +} +// CHECK-LABEL: define void @try_body(i32 %numerator, i32 %denominator, i32* %myres) +// CHECK: sdiv i32 +// CHECK: store i32 %{{.*}}, i32* +// CHECK: ret void -int SaveDiv(int numerator, int denominator, int *res) { +int safe_div(int numerator, int denominator, int *res) { int myres = 0; + int success = 1; __try { - myres = numerator / denominator; - __leave; + try_body(numerator, denominator, &myres); } __except (1) { - return 0; + success = -42; } *res = myres; - return 1; + return success; +} +// CHECK-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) +// CHECK: invoke void @try_body(i32 %{{.*}}, i32 %{{.*}}, i32* %{{.*}}) #[[NOINLINE:[0-9]+]] +// CHECK: to label %{{.*}} unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK-NEXT: catch i8* null +// CHECK-NOT: br i1 +// CHECK: br label %[[except:[^ ]*]] +// CHECK: [[except]] +// CHECK-NEXT: store i32 -42, i32* %[[success:[^ ]*]] +// +// CHECK: %[[res:[^ ]*]] = load i32, i32* %[[success]] +// CHECK: ret i32 %[[res]] + +void j(void); + +int filter_expr_capture(void) { + int r = 42; + __try { + j(); + } __except(r = -1) { + r = 13; + } + return r; +} + +// CHECK-LABEL: define i32 @filter_expr_capture() +// CHECK: call void (...) @llvm.frameescape(i32* %[[r:[^ ,]*]]) +// CHECK: store i32 42, i32* %[[r]] +// CHECK: invoke void @j() #[[NOINLINE]] +// +// CHECK: landingpad +// CHECK-NEXT: catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@filter_expr_capture@@" to i8*) +// CHECK: store i32 13, i32* %[[r]] +// +// CHECK: %[[rv:[^ ]*]] = load i32, i32* %[[r]] +// CHECK: ret i32 %[[rv]] + +// CHECK-LABEL: define internal i32 @"\01?filt$0@0@filter_expr_capture@@"(i8* %exception_pointers, i8* %frame_pointer) +// CHECK: call i8* @llvm.framerecover(i8* bitcast (i32 ()* @filter_expr_capture to i8*), i8* %frame_pointer, i32 0) +// CHECK: store i32 -1, i32* %{{.*}} +// CHECK: ret i32 -1 + +int nested_try(void) { + int r = 42; + __try { + __try { + j(); + r = 0; + } __except(_exception_code() == 123) { + r = 123; + } + } __except(_exception_code() == 456) { + r = 456; + } + return r; +} +// CHECK-LABEL: define i32 @nested_try() +// CHECK: store i32 42, i32* %[[r:[^ ,]*]] +// CHECK: invoke void @j() #[[NOINLINE]] +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[cont]] +// CHECK: store i32 0, i32* %[[r]] +// CHECK: br label %[[inner_try_cont:[^ ]*]] +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK: catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$1@0@nested_try@@" to i8*) +// CHECK: catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@nested_try@@" to i8*) +// CHECK: store i8* %{{.*}}, i8** %[[ehptr_slot:[^ ]*]] +// CHECK: store i32 %{{.*}}, i32* %[[sel_slot:[^ ]*]] +// +// CHECK: load i32, i32* %[[sel_slot]] +// CHECK: call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$1@0@nested_try@@" to i8*)) +// CHECK: icmp eq i32 +// CHECK: br i1 +// +// CHECK: load i32, i32* %[[sel_slot]] +// CHECK: call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@nested_try@@" to i8*)) +// CHECK: icmp eq i32 +// CHECK: br i1 +// +// CHECK: store i32 456, i32* %[[r]] +// CHECK: br label %[[outer_try_cont:[^ ]*]] +// +// CHECK: [[outer_try_cont]] +// CHECK: %[[r_load:[^ ]*]] = load i32, i32* %[[r]] +// CHECK: ret i32 %[[r_load]] +// +// CHECK: store i32 123, i32* %[[r]] +// CHECK: br label %[[inner_try_cont]] +// +// CHECK: [[inner_try_cont]] +// CHECK: br label %[[outer_try_cont]] + +static unsigned g = 0; +void basic_finally(void) { + ++g; + __try { + j(); + } __finally { + --g; + } } -// CHECK-NOT: error: -// CHECK: error: cannot compile this SEH __try yet -// CHECK-NOT: error: +// CHECK-LABEL: define void @basic_finally() +// CHECK: load i32, i32* @g +// CHECK: add i32 %{{.*}}, 1 +// CHECK: store i32 %{{.*}}, i32* @g +// +// CHECK: invoke void @j() +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[cont]] +// CHECK: %[[fp:[^ ]*]] = call i8* @llvm.frameaddress(i32 0) +// CHECK: call void @"\01?fin$0@0@basic_finally@@"(i8 0, i8* %[[fp]]) +// CHECK: ret void +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK-NEXT: cleanup +// CHECK: %[[fp:[^ ]*]] = call i8* @llvm.frameaddress(i32 0) +// CHECK: call void @"\01?fin$0@0@basic_finally@@"(i8 1, i8* %[[fp]]) +// CHECK: resume + +// CHECK: define internal void @"\01?fin$0@0@basic_finally@@"(i8 %abnormal_termination, i8* %frame_pointer) +// CHECK: load i32, i32* @g, align 4 +// CHECK: add i32 %{{.*}}, -1 +// CHECK: store i32 %{{.*}}, i32* @g, align 4 +// CHECK: ret void + +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, i32* %[[rv]] +// CHECK: ret i32 %[[r]] + +// CHECK: attributes #[[NOINLINE]] = { {{.*noinline.*}} } |