diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/exceptions-seh-finally.c | 38 | ||||
-rw-r--r-- | clang/test/CodeGen/exceptions-seh-leave.c | 19 | ||||
-rw-r--r-- | clang/test/CodeGen/exceptions-seh.c | 157 | ||||
-rw-r--r-- | clang/test/OpenMP/parallel_codegen.cpp | 8 | ||||
-rw-r--r-- | clang/test/Sema/__try.c | 36 | ||||
-rw-r--r-- | clang/test/SemaCXX/exceptions-seh.cpp | 48 |
6 files changed, 282 insertions, 24 deletions
diff --git a/clang/test/CodeGen/exceptions-seh-finally.c b/clang/test/CodeGen/exceptions-seh-finally.c new file mode 100644 index 00000000000..c8bf237f5a0 --- /dev/null +++ b/clang/test/CodeGen/exceptions-seh-finally.c @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fexceptions -fms-extensions -emit-llvm -o - | FileCheck %s + +void might_crash(void); +void cleanup(void); +int check_condition(void); +void basic_finally(void) { + __try { + might_crash(); + } __finally { + cleanup(); + } +} + +// CHECK-LABEL: define void @basic_finally() +// CHECK: invoke void @might_crash() +// CHECK: call void @cleanup() +// +// CHECK: landingpad +// CHECK-NEXT: cleanup +// CHECK: invoke void @cleanup() +// +// CHECK: landingpad +// CHECK-NEXT: catch i8* null +// CHECK: call void @abort() + +// FIXME: This crashes. +#if 0 +void basic_finally(void) { + __try { + might_crash(); + } __finally { +l: + cleanup(); + if (check_condition()) + goto l; + } +} +#endif diff --git a/clang/test/CodeGen/exceptions-seh-leave.c b/clang/test/CodeGen/exceptions-seh-leave.c new file mode 100644 index 00000000000..86161f297e4 --- /dev/null +++ b/clang/test/CodeGen/exceptions-seh-leave.c @@ -0,0 +1,19 @@ +// RUN: not %clang_cc1 -triple x86_64-pc-win32 -fexceptions -fms-extensions -emit-llvm -o - %s 2>&1 | FileCheck %s + +// This is a codegen test because we only emit the diagnostic when we start +// generating code. + +int SaveDiv(int numerator, int denominator, int *res) { + int myres = 0; + __try { + myres = numerator / denominator; + __leave; + } __except (1) { + return 0; + } + *res = myres; + return 1; +} +// CHECK-NOT: error: +// CHECK: error: cannot compile this SEH __leave yet +// CHECK-NOT: error: diff --git a/clang/test/CodeGen/exceptions-seh.c b/clang/test/CodeGen/exceptions-seh.c index 0a82e379b2c..ebf1cfbb2be 100644 --- a/clang/test/CodeGen/exceptions-seh.c +++ b/clang/test/CodeGen/exceptions-seh.c @@ -1,19 +1,154 @@ -// 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 -fexceptions -fms-extensions -emit-llvm -o - | FileCheck %s -// This is a codegen test because we only emit the diagnostic when we start -// generating code. +// FIXME: Perform this outlining automatically CodeGen. +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* %{{.*}}) +// CHECK: to label %{{.*}} unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK: %[[sel:[^ ]*]] = load i32* +// CHECK: %[[filt_id:[^ ]*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@safe_div@@" to i8*)) +// CHECK: %[[matches:[^ ]*]] = icmp eq i32 %[[sel]], %[[filt_id]] +// CHECK: br i1 %[[matches]], label %[[except_bb:[^ ]*]], label %{{.*}} +// +// CHECK: [[except_bb]] +// CHECK: store i32 -42, i32* %[[success:[^ ]*]] +// +// CHECK: %[[res:[^ ]*]] = load i32* %[[success]] +// CHECK: ret i32 %[[res]] + +void j(void); + +// FIXME: Implement local variable captures in filter expressions. +int filter_expr_capture() { + int r = 42; + __try { + j(); + } __except(/*r =*/ -1) { + r = 13; + } + return r; +} + +// CHECK-LABEL: define i32 @filter_expr_capture() +// FIXMECHECK: %[[captures]] = call i8* @llvm.frameallocate(i32 4) +// CHECK: store i32 42, i32* %[[r:[^ ,]*]] +// CHECK: invoke void @j() +// +// 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* %[[r]] +// CHECK: ret i32 %[[rv]] + +// CHECK-LABEL: define internal i32 @"\01?filt$0@0@filter_expr_capture@@"(i8* %exception_pointers, i8* %frame_pointer) +// FIXMECHECK: %[[captures]] = call i8* @llvm.framerecover(i8* bitcast (i32 ()* @filter_expr_capture, i8* %frame_pointer) +// FIXMECHECK: store i32 -1, i32* %{{.*}} +// CHECK: ret i32 -1 + +int nested_try() { + 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() +// 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* %[[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* %[[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* %[[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]] + +// FIXME: This lowering of __finally can't actually work, it will have to +// change. +static unsigned g = 0; +void basic_finally() { + ++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* @g +// CHECK: add i32 %{{.*}}, 1 +// CHECK: store i32 %{{.*}}, i32* @g +// +// CHECK: invoke void @j() +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[cont]] +// CHECK: load i32* @g +// CHECK: add i32 %{{.*}}, -1 +// CHECK: store i32 %{{.*}}, i32* @g +// CHECK: ret void +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK-NEXT: cleanup +// CHECK: load i32* @g +// CHECK: add i32 %{{.*}}, -1 +// CHECK: store i32 %{{.*}}, i32* @g +// CHECK: resume diff --git a/clang/test/OpenMP/parallel_codegen.cpp b/clang/test/OpenMP/parallel_codegen.cpp index e50ab43c280..ffaca9ab7f2 100644 --- a/clang/test/OpenMP/parallel_codegen.cpp +++ b/clang/test/OpenMP/parallel_codegen.cpp @@ -70,7 +70,7 @@ int main (int argc, char **argv) { // CHECK-NEXT: [[ARGC:%.+]] = load i32* [[ARGC_REF]] // CHECK-NEXT: invoke void [[FOO:@.+foo.+]](i32{{[ ]?[a-z]*}} [[ARGC]]) // CHECK: ret void -// CHECK: call void @{{.+terminate.*}}( +// CHECK: call void @{{.+terminate.*|abort}}( // CHECK-NEXT: unreachable // CHECK-NEXT: } // CHECK-DEBUG-LABEL: define internal void @.omp_outlined.(i32* %.global_tid., i32* %.bound_tid., %struct.anon* %__context) @@ -82,7 +82,7 @@ int main (int argc, char **argv) { // CHECK-DEBUG-NEXT: [[ARGC:%.+]] = load i32* [[ARGC_REF]] // CHECK-DEBUG-NEXT: invoke void [[FOO:@.+foo.+]](i32 [[ARGC]]) // CHECK-DEBUG: ret void -// CHECK-DEBUG: call void @{{.+terminate.*}}( +// CHECK-DEBUG: call void @{{.+terminate.*|abort}}( // CHECK-DEBUG-NEXT: unreachable // CHECK-DEBUG-NEXT: } @@ -123,7 +123,7 @@ int main (int argc, char **argv) { // CHECK-NEXT: [[ARGC:%.+]] = load i8*** [[ARGC_REF]] // CHECK-NEXT: invoke void [[FOO1:@.+foo.+]](i8** [[ARGC]]) // CHECK: ret void -// CHECK: call void @{{.+terminate.*}}( +// CHECK: call void @{{.+terminate.*|abort}}( // CHECK-NEXT: unreachable // CHECK-NEXT: } // CHECK-DEBUG-LABEL: define internal void @.omp_outlined.1(i32* %.global_tid., i32* %.bound_tid., %struct.anon.0* %__context) @@ -135,7 +135,7 @@ int main (int argc, char **argv) { // CHECK-DEBUG-NEXT: [[ARGC:%.+]] = load i8*** [[ARGC_REF]] // CHECK-DEBUG-NEXT: invoke void [[FOO1:@.+foo.+]](i8** [[ARGC]]) // CHECK-DEBUG: ret void -// CHECK-DEBUG: call void @{{.+terminate.*}}( +// CHECK-DEBUG: call void @{{.+terminate.*|abort}}( // CHECK-DEBUG-NEXT: unreachable // CHECK-DEBUG-NEXT: } diff --git a/clang/test/Sema/__try.c b/clang/test/Sema/__try.c index a355de9ccf9..607da9df27e 100644 --- a/clang/test/Sema/__try.c +++ b/clang/test/Sema/__try.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fborland-extensions -fsyntax-only -verify %s +// RUN: %clang_cc1 -fborland-extensions -DBORLAND -fsyntax-only -verify %s +// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s #define JOIN2(x,y) x ## y #define JOIN(x,y) JOIN2(x,y) @@ -10,8 +11,10 @@ typedef int DWORD; struct EXCEPTION_INFO{}; -int __exception_code(); +unsigned long __exception_code(); +#ifdef BORLAND struct EXCEPTION_INFO* __exception_info(); +#endif void __abnormal_termination(); #define GetExceptionCode __exception_code @@ -143,7 +146,11 @@ void TEST() { __except( function_scope ? 1 : -1 ) {} } +#ifdef BORLAND void TEST() { + (void)__abnormal_termination(); // expected-error{{only allowed in __finally block}} + (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}} + __try { (void)AbnormalTermination; // expected-error{{only allowed in __finally block}} (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} @@ -160,15 +167,27 @@ void TEST() { __abnormal_termination(); } } +#endif void TEST() { - (void)__exception_code; // expected-error{{only allowed in __except block}} - (void)__exception_info; // expected-error{{only allowed in __except filter expression}} - (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} - - (void)GetExceptionCode(); // expected-error{{only allowed in __except block}} + (void)__exception_info(); // expected-error{{only allowed in __except filter expression}} (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} - (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}} +} + +void TEST() { +#ifndef BORLAND + (void)__exception_code; // expected-error{{builtin functions must be directly called}} +#endif + (void)__exception_code(); // expected-error{{only allowed in __except block or filter expression}} + (void)GetExceptionCode(); // expected-error{{only allowed in __except block or filter expression}} +} + +void TEST() { + __try { + } __except(1) { + GetExceptionCode(); // valid + GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} + } } void test_seh_leave_stmt() { @@ -188,4 +207,3 @@ void test_seh_leave_stmt() { } __leave; // expected-error{{'__leave' statement not in __try block}} } - diff --git a/clang/test/SemaCXX/exceptions-seh.cpp b/clang/test/SemaCXX/exceptions-seh.cpp new file mode 100644 index 00000000000..8cc4b4fe3da --- /dev/null +++ b/clang/test/SemaCXX/exceptions-seh.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -verify %s + +// Basic usage should work. +int safe_div(int n, int d) { + int r; + __try { + r = n / d; + } __except(_exception_code() == 0xC0000094) { + r = 0; + } + return r; +} + +void might_crash(); + +// Diagnose obvious builtin mis-usage. +void bad_builtin_scope() { + __try { + might_crash(); + } __except(1) { + } + _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}} + _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}} +} + +// Diagnose obvious builtin misusage in a template. +template <void FN()> +void bad_builtin_scope_template() { + __try { + FN(); + } __except(1) { + } + _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}} + _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}} +} +void instantiate_bad_scope_tmpl() { + bad_builtin_scope_template<might_crash>(); +} + +// FIXME: Diagnose this case. For now we produce undef in codegen. +template <typename T, T FN()> +T func_template() { + return FN(); +} +void inject_builtins() { + func_template<void *, __exception_info>(); + func_template<unsigned long, __exception_code>(); +} |