diff options
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CodeGenCXX/exceptions-seh.cpp | 76 | ||||
| -rw-r--r-- | clang/test/SemaCXX/exceptions-seh.cpp | 47 |
2 files changed, 122 insertions, 1 deletions
diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp new file mode 100644 index 00000000000..74b43a94f64 --- /dev/null +++ b/clang/test/CodeGenCXX/exceptions-seh.cpp @@ -0,0 +1,76 @@ +// RUN: %clang_cc1 -std=c++11 -fblocks -fms-extensions %s -triple=x86_64-windows-msvc -emit-llvm -o - -fcxx-exceptions -fexceptions -mconstructor-aliases | FileCheck %s + +extern "C" void might_throw(); + +struct HasCleanup { + HasCleanup(); + ~HasCleanup(); + int padding; +}; + +extern "C" void use_cxx() { + HasCleanup x; + might_throw(); +} + +// Make sure we use __CxxFrameHandler3 for C++ EH. + +// CHECK-LABEL: define void @use_cxx() +// CHECK: call %struct.HasCleanup* @"\01??0HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) +// CHECK: invoke void @might_throw() +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[cont]] +// CHECK: call void @"\01??1HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) +// CHECK: ret void +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) +// CHECK-NEXT: cleanup +// CHECK: call void @"\01??1HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) +// CHECK: br label %[[resume:[^ ]*]] +// +// CHECK: [[resume]] +// CHECK: resume + +extern "C" void use_seh() { + __try { + might_throw(); + } __except(1) { + } +} + +// Make sure we use __C_specific_handler for SEH. + +// CHECK-LABEL: define void @use_seh() +// CHECK: invoke void @might_throw() +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// +// CHECK: [[cont]] +// CHECK: br label %[[ret:[^ ]*]] +// +// CHECK: [[lpad]] +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// CHECK-NEXT: catch i8* +// +// CHECK: br label %[[ret]] +// +// CHECK: [[ret]] +// CHECK: ret void + +void use_seh_in_lambda() { + ([]() { + __try { + might_throw(); + } __except(1) { + } + })(); + HasCleanup x; + might_throw(); +} + +// CHECK-LABEL: define void @"\01?use_seh_in_lambda@@YAXXZ"() +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) + +// CHECK-LABEL: define internal void @"\01??R<lambda_0>@?use_seh_in_lambda@@YAXXZ@QEBAXXZ"(%class.anon* %this) +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) diff --git a/clang/test/SemaCXX/exceptions-seh.cpp b/clang/test/SemaCXX/exceptions-seh.cpp index dd00c11590a..7375ec9bf81 100644 --- a/clang/test/SemaCXX/exceptions-seh.cpp +++ b/clang/test/SemaCXX/exceptions-seh.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -std=c++03 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -std=c++11 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s // Basic usage should work. int safe_div(int n, int d) { @@ -37,6 +38,7 @@ void instantiate_bad_scope_tmpl() { bad_builtin_scope_template<might_crash>(); } +#if __cplusplus < 201103L // FIXME: Diagnose this case. For now we produce undef in codegen. template <typename T, T FN()> T func_template() { @@ -46,6 +48,7 @@ void inject_builtins() { func_template<void *, __exception_info>(); func_template<unsigned long, __exception_code>(); } +#endif void use_seh_after_cxx() { try { // expected-note {{conflicting 'try' here}} @@ -68,3 +71,45 @@ void use_cxx_after_seh() { } catch (int) { } } + +#if __cplusplus >= 201103L +void use_seh_in_lambda() { + ([]() { + __try { + might_crash(); + } __except(1) { + } + })(); + try { + might_crash(); + } catch (int) { + } +} +#endif + +void use_seh_in_block() { + void (^b)() = ^{ + __try { // expected-error {{cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls}} + might_crash(); + } __except(1) { + } + }; + try { + b(); + } catch (int) { + } +} + +void (^use_seh_in_global_block)() = ^{ + __try { // expected-error {{cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls}} + might_crash(); + } __except(1) { + } +}; + +void (^use_cxx_in_global_block)() = ^{ + try { + might_crash(); + } catch(int) { + } +}; |

