xref: /llvm-project/clang/test/CodeGen/windows-seh-EHa-CppDtors01.cpp (revision c5de4dd1eab00df76c1a68c5f397304ceacb71f2)
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: invoke void @llvm.seh.scope.begin()
4 // CHECK: invoke void @llvm.seh.scope.begin()
5 // CHECK: invoke void @llvm.seh.scope.begin()
6 // CHECK: invoke void @llvm.seh.scope.end()
7 // CHECK: invoke void @llvm.seh.scope.end()
8 // CHECK: invoke void @llvm.seh.scope.end()
9 
10 // CHECK: invoke void @llvm.seh.try.begin()
11 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
12 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
13 // CHECK: invoke void @llvm.seh.try.end()
14 
15 // ****************************************************************************
16 // Abstract:     Test CPP unwind Dtoring under SEH -EHa option
17 
18 void printf(...);
19 int volatile *NullPtr = 0;
crash(int i)20 void crash(int i) {
21   struct A {
22     ~A() {
23       printf(" in A dtor \n");
24     }
25   } ObjA;
26   if (i == 0)
27     *NullPtr = 0;
28 
29   struct B {
30     ~B() {
31       printf(" in B dtor \n");
32     }
33   } ObjB;
34   if (i == 1)
35     *NullPtr = 0;
36 
37   struct C {
38     ~C() {
39       printf(" in C dtor \n");
40     }
41   } ObjC;
42   if (i == 2)
43     *NullPtr = 0;
44 }
45 
46 #define TRY __try
47 #define CATCH_ALL __except (1)
48 
49 int g;
main()50 int main() {
51   for (int i = 0; i < 3; i++) {
52     TRY {
53       crash(i);
54     }
55     CATCH_ALL {
56       printf(" Test CPP unwind: in catch handler i = %d \n", i);
57     }
58   }
59   return 0;
60 }
61