1 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc \
2 // RUN: -mconstructor-aliases -fexceptions -fcxx-exceptions \
3 // RUN: -O1 -disable-llvm-passes \
4 // RUN: | FileCheck -check-prefix WIN64 %s
6 extern "C" void might_throw();
8 // Simplify the generated IR with noexcept.
9 extern "C" void recover() noexcept(true);
10 extern "C" void handle_exception(void *e
) noexcept(true);
12 extern "C" void catch_all() {
20 // WIN64-LABEL: define dso_local void @catch_all()
21 // WIN64: invoke void @might_throw()
22 // WIN64-NEXT: to label %[[cont:[^ ]*]] unwind label %[[catchswitch_lpad:[^ ]*]]
24 // WIN64: [[catchswitch_lpad]]
25 // WIN64: %[[catchswitch:[^ ]*]] = catchswitch within none [label %[[catchpad_lpad:[^ ]*]]] unwind to caller
27 // WIN64: [[catchpad_lpad]]
28 // WIN64: catchpad within %[[catchswitch]] [ptr null, i32 64, ptr null]
29 // WIN64: call void @recover()
30 // WIN64: catchret from %{{.*}} to label %[[catchret:[^ ]*]]
32 // WIN64: [[catchret]]
33 // WIN64-NEXT: br label %[[ret:[^ ]*]]
39 // WIN64: br label %[[ret]]
41 extern "C" void catch_int() {
49 // WIN64-LABEL: define dso_local void @catch_int()
50 // WIN64: catchpad within %{{[^ ]*}} [ptr @"??_R0H@8", i32 0, ptr %[[e_addr:.*]]]
52 // The catchpad instruction starts the lifetime of 'e'. Unfortunately, that
53 // leaves us with nowhere to put lifetime.start, so we don't emit lifetime
55 // WIN64-NOT: lifetime.start
57 // WIN64-NOT: lifetime.start
58 // WIN64: call void @handle_exception
59 // WIN64-SAME: (ptr noundef %[[e_addr]])
60 // WIN64-NOT: lifetime.end
63 extern "C" void catch_int_unnamed() {
70 // WIN64-LABEL: define dso_local void @catch_int_unnamed()
71 // WIN64: catchpad within %{{.*}} [ptr @"??_R0H@8", i32 0, ptr null]
88 extern "C" void catch_a_byval() {
96 // WIN64-LABEL: define dso_local void @catch_a_byval()
97 // WIN64: %[[e_addr:[^ ]*]] = alloca %struct.A
98 // WIN64: catchpad within %{{[^ ]*}} [ptr @"??_R0?AUA@@@8", i32 0, ptr %[[e_addr]]]
99 // WIN64: call void @handle_exception(ptr noundef %[[e_addr]])
102 extern "C" void catch_a_ref() {
106 handle_exception(&e
);
110 // WIN64-LABEL: define dso_local void @catch_a_ref()
111 // WIN64: %[[e_addr:[^ ]*]] = alloca ptr
112 // WIN64: catchpad within %{{[^ ]*}} [ptr @"??_R0?AUA@@@8", i32 8, ptr %[[e_addr]]]
113 // WIN64: %[[eptr:[^ ]*]] = load ptr, ptr %[[e_addr]]
114 // WIN64: call void @handle_exception(ptr noundef %[[eptr]])
117 extern "C" void fn_with_exc_spec() throw(int) {
121 // WIN64-LABEL: define dso_local void @fn_with_exc_spec()
122 // WIN64: call void @might_throw()
123 // WIN64-NEXT: ret void
125 extern "C" void catch_nested() {
137 // WIN64-LABEL: define dso_local void @catch_nested()
138 // WIN64: invoke void @might_throw()
139 // WIN64-NEXT: to label %{{.*}} unwind label %[[catchswitch_outer:[^ ]*]]
141 // WIN64: [[catchswitch_outer]]
142 // WIN64: %[[catchswitch_outer_scope:[^ ]*]] = catchswitch within none [label %[[catch_int_outer:[^ ]*]]] unwind to caller
144 // WIN64: [[catch_int_outer]]
145 // WIN64: %[[catchpad:[^ ]*]] = catchpad within %[[catchswitch_outer_scope]] [ptr @"??_R0H@8", i32 0, ptr null]
146 // WIN64: invoke void @might_throw()
147 // WIN64-NEXT: to label %[[cont2:[^ ]*]] unwind label %[[catchswitch_inner:[^ ]*]]
149 // WIN64: [[catchswitch_inner]]
150 // WIN64: %[[catchswitch_inner_scope:[^ ]*]] = catchswitch within %[[catchpad]] [label %[[catch_int_inner:[^ ]*]]] unwind to caller
152 // WIN64: [[catch_int_inner]]
153 // WIN64: catchpad within %[[catchswitch_inner_scope]] [ptr @"??_R0H@8", i32 0, ptr null]
154 // WIN64-NEXT: call void @might_throw()
155 // WIN64: catchret {{.*}} to label %[[catchret2:[^ ]*]]
157 // WIN64: [[catchret2]]
158 // WIN64: catchret {{.*}} to label %[[mainret:[^ ]*]]
160 // WIN64: [[mainret]]