| 1 |
// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -emit-llvm %s -o - | FileCheck %s |
| 2 |
|
| 3 |
// CHECK: define dso_local void @"?crash@@YAXH@Z |
| 4 |
// CHECK: invoke void @llvm.seh.try.begin() |
| 5 |
// CHECK: invoke void @llvm.seh.scope.begin() |
| 6 |
// CHECK: invoke void @llvm.seh.scope.end() |
| 7 |
|
| 8 |
// CHECK: %[[dst:[0-9-]+]] = catchswitch within none [label %catch] unwind to caller |
| 9 |
// CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr null] |
| 10 |
// CHECK: "funclet"(token %[[dst1]]) |
| 11 |
|
| 12 |
// CHECK: define dso_local void @"?bar@@YAXXZ |
| 13 |
// CHECK: invoke void @llvm.seh.try.begin() |
| 14 |
// CHECK: invoke void @_CxxThrowException |
| 15 |
// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null] |
| 16 |
// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ] |
| 17 |
|
| 18 |
// CHECK: invoke void @llvm.seh.try.begin() |
| 19 |
// CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i |
| 20 |
// CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]]) |
| 21 |
// CHECK: invoke void @llvm.seh.try.end() |
| 22 |
|
| 23 |
// CHECK: invoke void @llvm.seh.try.begin() |
| 24 |
// CHECK: invoke void @"?bar@@YAXXZ"() |
| 25 |
// CHECK: invoke void @llvm.seh.try.end() |
| 26 |
|
| 27 |
// ***************************************************************************** |
| 28 |
// Abstract: Test CPP catch(...) under SEH -EHa option |
| 29 |
|
| 30 |
void printf(...); |
| 31 |
int volatile *NullPtr = 0; |
| 32 |
void foo() { |
| 33 |
*NullPtr = 0; |
| 34 |
} |
| 35 |
int *pt1, *pt2, *pt3; |
| 36 |
int g; |
| 37 |
void crash(int i) { |
| 38 |
g = i; |
| 39 |
try { |
| 40 |
struct A { |
| 41 |
A() { |
| 42 |
printf(" in A ctor \n"); |
| 43 |
if (g == 0) |
| 44 |
*NullPtr = 0; |
| 45 |
} |
| 46 |
~A() { |
| 47 |
printf(" in A dtor \n"); |
| 48 |
} |
| 49 |
} ObjA; |
| 50 |
if (i == 1) |
| 51 |
*NullPtr = 0; |
| 52 |
} catch (...) { |
| 53 |
printf(" in catch(...) funclet \n"); |
| 54 |
if (i == 1) |
| 55 |
throw(i); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
void bar() { |
| 60 |
try { |
| 61 |
throw 1; |
| 62 |
} catch(...) { |
| 63 |
try { |
| 64 |
*NullPtr = 0; |
| 65 |
} catch (...) { |
| 66 |
throw 1; |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
int main() { |
| 72 |
for (int i = 0; i < 2; i++) { |
| 73 |
__try { |
| 74 |
crash(i); |
| 75 |
} __except (1) { |
| 76 |
printf(" Test CPP unwind: in except handler i = %d \n", i); |
| 77 |
} |
| 78 |
} |
| 79 |
__try { |
| 80 |
bar(); |
| 81 |
} __except (1) { |
| 82 |
printf("Test CPP unwind: in except handler \n"); |
| 83 |
} |
| 84 |
return 0; |
| 85 |
} |