Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc \ |
David Majnemer | 4ff6f73 | 2016-02-20 09:23:41 +0000 | [diff] [blame] | 2 | // RUN: -mconstructor-aliases -fexceptions -fcxx-exceptions \ |
Reid Kleckner | 1f88e93 | 2015-10-07 21:03:41 +0000 | [diff] [blame] | 3 | // RUN: -O1 -disable-llvm-optzns \ |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 4 | // RUN: | FileCheck -check-prefix WIN64 %s |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 5 | |
| 6 | extern "C" void might_throw(); |
| 7 | |
| 8 | // Simplify the generated IR with noexcept. |
| 9 | extern "C" void recover() noexcept(true); |
| 10 | extern "C" void handle_exception(void *e) noexcept(true); |
| 11 | |
| 12 | extern "C" void catch_all() { |
| 13 | try { |
| 14 | might_throw(); |
| 15 | } catch (...) { |
| 16 | recover(); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // WIN64-LABEL: define void @catch_all() |
| 21 | // WIN64: invoke void @might_throw() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 22 | // WIN64-NEXT: to label %[[cont:[^ ]*]] unwind label %[[catchswitch_lpad:[^ ]*]] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 23 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 24 | // WIN64: [[catchswitch_lpad]] |
| 25 | // WIN64: %[[catchswitch:[^ ]*]] = catchswitch within none [label %[[catchpad_lpad:[^ ]*]]] unwind to caller |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 26 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 27 | // WIN64: [[catchpad_lpad]] |
| 28 | // WIN64: catchpad within %[[catchswitch]] [i8* null, i32 64, i8* null] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 29 | // WIN64: call void @recover() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 30 | // WIN64: catchret from %{{.*}} to label %[[catchret:[^ ]*]] |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 31 | // |
| 32 | // WIN64: [[catchret]] |
| 33 | // WIN64-NEXT: br label %[[ret:[^ ]*]] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 34 | // |
| 35 | // WIN64: [[ret]] |
| 36 | // WIN64: ret void |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 37 | // |
| 38 | // WIN64: [[cont]] |
| 39 | // WIN64: br label %[[ret]] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 40 | |
| 41 | extern "C" void catch_int() { |
| 42 | try { |
| 43 | might_throw(); |
| 44 | } catch (int e) { |
| 45 | handle_exception(&e); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // WIN64-LABEL: define void @catch_int() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 50 | // WIN64: catchpad within %{{[^ ]*}} [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %[[e_addr:[^\]]*]]] |
Reid Kleckner | 1f88e93 | 2015-10-07 21:03:41 +0000 | [diff] [blame] | 51 | // |
| 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 |
| 54 | // markers for now. |
| 55 | // WIN64-NOT: lifetime.start |
| 56 | // |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 57 | // WIN64: %[[e_i8:[^ ]*]] = bitcast i32* %[[e_addr]] to i8* |
Reid Kleckner | 1f88e93 | 2015-10-07 21:03:41 +0000 | [diff] [blame] | 58 | // WIN64-NOT: lifetime.start |
| 59 | // WIN64: call void @handle_exception |
| 60 | // WIN64-SAME: (i8* %[[e_i8]]) |
| 61 | // WIN64-NOT: lifetime.end |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 62 | // WIN64: catchret |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 63 | |
Reid Kleckner | 67cf035 | 2015-04-07 00:09:59 +0000 | [diff] [blame] | 64 | extern "C" void catch_int_unnamed() { |
| 65 | try { |
| 66 | might_throw(); |
| 67 | } catch (int) { |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // WIN64-LABEL: define void @catch_int_unnamed() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 72 | // WIN64: catchpad within %{{.*}} [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null] |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 73 | // WIN64: catchret |
Reid Kleckner | 67cf035 | 2015-04-07 00:09:59 +0000 | [diff] [blame] | 74 | |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 75 | struct A { |
| 76 | A(); |
| 77 | A(const A &o); |
| 78 | ~A(); |
| 79 | int a; |
| 80 | }; |
| 81 | |
| 82 | struct B : A { |
| 83 | B(); |
| 84 | B(const B &o); |
| 85 | ~B(); |
| 86 | int b; |
| 87 | }; |
| 88 | |
| 89 | extern "C" void catch_a_byval() { |
| 90 | try { |
| 91 | might_throw(); |
| 92 | } catch (A e) { |
| 93 | handle_exception(&e); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // WIN64-LABEL: define void @catch_a_byval() |
| 98 | // WIN64: %[[e_addr:[^ ]*]] = alloca %struct.A |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 99 | // WIN64: catchpad within %{{[^ ]*}} [%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8", i32 0, %struct.A* %[[e_addr]]] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 100 | // WIN64: %[[e_i8:[^ ]*]] = bitcast %struct.A* %[[e_addr]] to i8* |
| 101 | // WIN64: call void @handle_exception(i8* %[[e_i8]]) |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 102 | // WIN64: catchret |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 103 | |
| 104 | extern "C" void catch_a_ref() { |
| 105 | try { |
| 106 | might_throw(); |
| 107 | } catch (A &e) { |
| 108 | handle_exception(&e); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // WIN64-LABEL: define void @catch_a_ref() |
| 113 | // WIN64: %[[e_addr:[^ ]*]] = alloca %struct.A* |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 114 | // WIN64: catchpad within %{{[^ ]*}} [%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8", i32 8, %struct.A** %[[e_addr]]] |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 115 | // WIN64: %[[eptr:[^ ]*]] = load %struct.A*, %struct.A** %[[e_addr]] |
| 116 | // WIN64: %[[eptr_i8:[^ ]*]] = bitcast %struct.A* %[[eptr]] to i8* |
| 117 | // WIN64: call void @handle_exception(i8* %[[eptr_i8]]) |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 118 | // WIN64: catchret |
David Majnemer | 1f192e2 | 2015-04-01 04:45:52 +0000 | [diff] [blame] | 119 | |
| 120 | extern "C" void fn_with_exc_spec() throw(int) { |
| 121 | might_throw(); |
| 122 | } |
| 123 | |
| 124 | // WIN64-LABEL: define void @fn_with_exc_spec() |
| 125 | // WIN64: call void @might_throw() |
| 126 | // WIN64-NEXT: ret void |
Reid Kleckner | 7d4bc9c | 2015-04-22 23:39:15 +0000 | [diff] [blame] | 127 | |
| 128 | extern "C" void catch_nested() { |
| 129 | try { |
| 130 | might_throw(); |
| 131 | } catch (int) { |
| 132 | try { |
| 133 | might_throw(); |
| 134 | } catch (int) { |
| 135 | might_throw(); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // WIN64-LABEL: define void @catch_nested() |
| 141 | // WIN64: invoke void @might_throw() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 142 | // WIN64-NEXT: to label %{{.*}} unwind label %[[catchswitch_outer:[^ ]*]] |
Reid Kleckner | 7d4bc9c | 2015-04-22 23:39:15 +0000 | [diff] [blame] | 143 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 144 | // WIN64: [[catchswitch_outer]] |
| 145 | // WIN64: %[[catchswitch_outer_scope:[^ ]*]] = catchswitch within none [label %[[catch_int_outer:[^ ]*]]] unwind to caller |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 146 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 147 | // WIN64: [[catch_int_outer]] |
| 148 | // WIN64: %[[catchpad:[^ ]*]] = catchpad within %[[catchswitch_outer_scope]] [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null] |
Reid Kleckner | 7d4bc9c | 2015-04-22 23:39:15 +0000 | [diff] [blame] | 149 | // WIN64: invoke void @might_throw() |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 150 | // WIN64-NEXT: to label %[[cont2:[^ ]*]] unwind label %[[catchswitch_inner:[^ ]*]] |
Reid Kleckner | 7d4bc9c | 2015-04-22 23:39:15 +0000 | [diff] [blame] | 151 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 152 | // WIN64: [[catchswitch_inner]] |
| 153 | // WIN64: %[[catchswitch_inner_scope:[^ ]*]] = catchswitch within %[[catchpad]] [label %[[catch_int_inner:[^ ]*]]] unwind to caller |
Reid Kleckner | 7d4bc9c | 2015-04-22 23:39:15 +0000 | [diff] [blame] | 154 | // |
David Majnemer | 4e52d6f | 2015-12-12 05:39:21 +0000 | [diff] [blame] | 155 | // WIN64: [[catch_int_inner]] |
| 156 | // WIN64: catchpad within %[[catchswitch_inner_scope]] [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null] |
| 157 | // WIN64-NEXT: call void @might_throw() |
Reid Kleckner | 10aa770 | 2015-09-16 20:15:55 +0000 | [diff] [blame] | 158 | // WIN64: catchret {{.*}} to label %[[catchret2:[^ ]*]] |
| 159 | // |
| 160 | // WIN64: [[catchret2]] |
| 161 | // WIN64: catchret {{.*}} to label %[[mainret:[^ ]*]] |
| 162 | // |
| 163 | // WIN64: [[mainret]] |
| 164 | // WIN64: ret void |