Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 -fno-rtti > %t |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 2 | // RUN: FileCheck %s < %t |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 3 | // vftables are emitted very late, so do another pass to try to keep the checks |
| 4 | // in source order. |
| 5 | // RUN: FileCheck --check-prefix DTORS %s < %t |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 6 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 7 | namespace basic { |
| 8 | |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 9 | class A { |
| 10 | public: |
| 11 | A() { } |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 12 | ~A(); |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 13 | }; |
| 14 | |
Timur Iskhodzhanov | 6c9dccd | 2013-02-12 13:22:47 +0000 | [diff] [blame] | 15 | void no_constructor_destructor_infinite_recursion() { |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 16 | A a; |
| 17 | |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 18 | // CHECK: define linkonce_odr x86_thiscallcc %"class.basic::A"* @"\01??0A@basic@@QAE@XZ"(%"class.basic::A"* returned %this) |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 19 | // CHECK: [[THIS_ADDR:%[.0-9A-Z_a-z]+]] = alloca %"class.basic::A"*, align 4 |
| 20 | // CHECK-NEXT: store %"class.basic::A"* %this, %"class.basic::A"** [[THIS_ADDR]], align 4 |
| 21 | // CHECK-NEXT: [[T1:%[.0-9A-Z_a-z]+]] = load %"class.basic::A"** [[THIS_ADDR]] |
| 22 | // CHECK-NEXT: ret %"class.basic::A"* [[T1]] |
John McCall | bd31574 | 2012-09-25 08:00:39 +0000 | [diff] [blame] | 23 | // CHECK-NEXT: } |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 24 | } |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 25 | |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 26 | A::~A() { |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 27 | // Make sure that the destructor doesn't call itself: |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 28 | // CHECK: define {{.*}} @"\01??1A@basic@@QAE@XZ" |
| 29 | // CHECK-NOT: call void @"\01??1A@basic@@QAE@XZ" |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 30 | // CHECK: ret |
| 31 | } |
John McCall | bd31574 | 2012-09-25 08:00:39 +0000 | [diff] [blame] | 32 | |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 33 | struct B { |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 34 | B(); |
| 35 | }; |
| 36 | |
| 37 | // Tests that we can define constructors outside the class (PR12784). |
| 38 | B::B() { |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 39 | // CHECK: define x86_thiscallcc %"struct.basic::B"* @"\01??0B@basic@@QAE@XZ"(%"struct.basic::B"* returned %this) |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 40 | // CHECK: ret |
| 41 | } |
| 42 | |
| 43 | struct C { |
| 44 | virtual ~C() { |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 45 | // DTORS: define linkonce_odr x86_thiscallcc void @"\01??_GC@basic@@UAEPAXI@Z"(%"struct.basic::C"* %this, i1 zeroext %should_call_delete) |
Timur Iskhodzhanov | 4745345 | 2013-02-13 12:14:25 +0000 | [diff] [blame] | 46 | // DTORS: %[[FROMBOOL:[0-9a-z]+]] = zext i1 %should_call_delete to i8 |
Timur Iskhodzhanov | ba8fa0c | 2013-02-13 12:24:19 +0000 | [diff] [blame] | 47 | // DTORS-NEXT: store i8 %[[FROMBOOL]], i8* %[[SHOULD_DELETE_VAR:[0-9a-z._]+]], align 1 |
| 48 | // DTORS: %[[SHOULD_DELETE_VALUE:[0-9a-z._]+]] = load i8* %[[SHOULD_DELETE_VAR]] |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 49 | // DTORS: call x86_thiscallcc void @"\01??1C@basic@@UAE@XZ"(%"struct.basic::C"* %[[THIS:[0-9a-z]+]]) |
Timur Iskhodzhanov | 4745345 | 2013-02-13 12:14:25 +0000 | [diff] [blame] | 50 | // DTORS-NEXT: %[[CONDITION:[0-9]+]] = icmp eq i8 %[[SHOULD_DELETE_VALUE]], 0 |
| 51 | // DTORS-NEXT: br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]] |
| 52 | // |
| 53 | // DTORS: [[CALL_DELETE_LABEL]] |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 54 | // DTORS-NEXT: %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8* |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 55 | // DTORS-NEXT: call void @"\01??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]]) |
Timur Iskhodzhanov | 4745345 | 2013-02-13 12:14:25 +0000 | [diff] [blame] | 56 | // DTORS-NEXT: br label %[[CONTINUE_LABEL]] |
| 57 | // |
| 58 | // DTORS: [[CONTINUE_LABEL]] |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 59 | // DTORS-NEXT: ret void |
| 60 | } |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 61 | virtual void foo(); |
| 62 | }; |
| 63 | |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 64 | // Emits the vftable in the output. |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 65 | void C::foo() {} |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 66 | |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 67 | void check_vftable_offset() { |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 68 | C c; |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 69 | // The vftable pointer should point at the beginning of the vftable. |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 70 | // CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %"struct.basic::C"* {{.*}} to i8*** |
| 71 | // CHECK: store i8** getelementptr inbounds ([2 x i8*]* @"\01??_7C@basic@@6B@", i64 0, i64 0), i8*** [[THIS_PTR]] |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 72 | } |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 73 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 74 | void call_complete_dtor(C *obj_ptr) { |
| 75 | // CHECK: define void @"\01?call_complete_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr) |
| 76 | obj_ptr->~C(); |
| 77 | // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4 |
| 78 | // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to void (%"struct.basic::C"*, i1)*** |
| 79 | // CHECK-NEXT: %[[VTABLE:.*]] = load void (%"struct.basic::C"*, i1)*** %[[PVTABLE]] |
| 80 | // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds void (%"struct.basic::C"*, i1)** %[[VTABLE]], i64 0 |
| 81 | // CHECK-NEXT: %[[VDTOR:.*]] = load void (%"struct.basic::C"*, i1)** %[[PVDTOR]] |
| 82 | // CHECK-NEXT: call x86_thiscallcc void %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i1 zeroext false) |
Timur Iskhodzhanov | 0f9827f | 2013-02-15 14:45:22 +0000 | [diff] [blame] | 83 | // CHECK-NEXT: ret void |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 84 | } |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 85 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 86 | void call_deleting_dtor(C *obj_ptr) { |
| 87 | // CHECK: define void @"\01?call_deleting_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr) |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 88 | delete obj_ptr; |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 89 | // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4 |
| 90 | // CHECK: br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]] |
| 91 | |
| 92 | // CHECK: [[DELETE_NOTNULL]] |
| 93 | // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to void (%"struct.basic::C"*, i1)*** |
| 94 | // CHECK-NEXT: %[[VTABLE:.*]] = load void (%"struct.basic::C"*, i1)*** %[[PVTABLE]] |
| 95 | // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds void (%"struct.basic::C"*, i1)** %[[VTABLE]], i64 0 |
| 96 | // CHECK-NEXT: %[[VDTOR:.*]] = load void (%"struct.basic::C"*, i1)** %[[PVDTOR]] |
| 97 | // CHECK-NEXT: call x86_thiscallcc void %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i1 zeroext true) |
Timur Iskhodzhanov | 0f9827f | 2013-02-15 14:45:22 +0000 | [diff] [blame] | 98 | // CHECK: ret void |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 101 | struct D { |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 102 | static int foo(); |
| 103 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 104 | D() { |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 105 | static int ctor_static = foo(); |
| 106 | // CHECK that the static in the ctor gets mangled correctly: |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 107 | // CHECK: @"\01?ctor_static@?1???0D@basic@@QAE@XZ@4HA" |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 108 | } |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 109 | ~D() { |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 110 | static int dtor_static = foo(); |
| 111 | // CHECK that the static in the dtor gets mangled correctly: |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 112 | // CHECK: @"\01?dtor_static@?1???1D@basic@@QAE@XZ@4HA" |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 113 | } |
| 114 | }; |
| 115 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 116 | void use_D() { D c; } |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 117 | |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 118 | } // end namespace basic |
| 119 | |
| 120 | |
| 121 | namespace constructors { |
| 122 | |
| 123 | struct A { |
| 124 | A() {} |
| 125 | }; |
| 126 | |
| 127 | struct B : A { |
| 128 | B(); |
| 129 | ~B(); |
| 130 | }; |
| 131 | |
| 132 | B::B() { |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 133 | // CHECK: define x86_thiscallcc %"struct.constructors::B"* @"\01??0B@constructors@@QAE@XZ"(%"struct.constructors::B"* returned %this) |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 134 | // CHECK: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}}) |
| 135 | // CHECK: ret |
| 136 | } |
| 137 | |
| 138 | struct C : virtual A { |
| 139 | C(); |
| 140 | }; |
| 141 | |
| 142 | C::C() { |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 143 | // CHECK: define x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* returned %this, i32 %is_most_derived) |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 144 | // TODO: make sure this works in the Release build too; |
| 145 | // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4 |
| 146 | // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]] |
| 147 | // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0 |
| 148 | // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] |
| 149 | // |
| 150 | // CHECK: [[INIT_VBASES]] |
Reid Kleckner | 9063302 | 2013-06-19 15:20:38 +0000 | [diff] [blame] | 151 | // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::C"* %{{.*}} to i8* |
| 152 | // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0 |
| 153 | // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to [2 x i32]** |
| 154 | // CHECK-NEXT: store [2 x i32]* @"\01??_8C@constructors@@7B@", [2 x i32]** %[[vbptr]] |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 155 | // CHECK-NEXT: bitcast %"struct.constructors::C"* %{{.*}} to %"struct.constructors::A"* |
| 156 | // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}}) |
| 157 | // CHECK-NEXT: br label %[[SKIP_VBASES]] |
| 158 | // |
| 159 | // CHECK: [[SKIP_VBASES]] |
| 160 | // CHECK: @"\01??_7C@constructors@@6B@" |
| 161 | // CHECK: ret |
| 162 | } |
| 163 | |
| 164 | void create_C() { |
| 165 | C c; |
| 166 | // CHECK: define void @"\01?create_C@constructors@@YAXXZ"() |
| 167 | // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %c, i32 1) |
| 168 | // CHECK: ret |
| 169 | } |
| 170 | |
| 171 | struct D : C { |
| 172 | D(); |
| 173 | }; |
| 174 | |
| 175 | D::D() { |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 176 | // CHECK: define x86_thiscallcc %"struct.constructors::D"* @"\01??0D@constructors@@QAE@XZ"(%"struct.constructors::D"* returned %this, i32 %is_most_derived) unnamed_addr |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 177 | // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4 |
| 178 | // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]] |
| 179 | // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0 |
| 180 | // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] |
| 181 | // |
| 182 | // CHECK: [[INIT_VBASES]] |
Reid Kleckner | 9063302 | 2013-06-19 15:20:38 +0000 | [diff] [blame] | 183 | // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::D"* %{{.*}} to i8* |
| 184 | // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0 |
| 185 | // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to [2 x i32]** |
| 186 | // CHECK-NEXT: store [2 x i32]* @"\01??_8D@constructors@@7B@", [2 x i32]** %[[vbptr]] |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 187 | // CHECK-NEXT: bitcast %"struct.constructors::D"* %{{.*}} to %"struct.constructors::A"* |
| 188 | // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}}) |
| 189 | // CHECK-NEXT: br label %[[SKIP_VBASES]] |
| 190 | // |
| 191 | // CHECK: [[SKIP_VBASES]] |
| 192 | // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0) |
| 193 | // CHECK: ret |
| 194 | } |
| 195 | |
| 196 | struct E : virtual C { |
| 197 | E(); |
| 198 | }; |
| 199 | |
| 200 | E::E() { |
Stephen Lin | 3b50e8d | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 201 | // CHECK: define x86_thiscallcc %"struct.constructors::E"* @"\01??0E@constructors@@QAE@XZ"(%"struct.constructors::E"* returned %this, i32 %is_most_derived) unnamed_addr |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 202 | // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4 |
| 203 | // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]] |
| 204 | // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0 |
| 205 | // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] |
| 206 | // |
| 207 | // CHECK: [[INIT_VBASES]] |
Reid Kleckner | 9063302 | 2013-06-19 15:20:38 +0000 | [diff] [blame] | 208 | // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::E"* %{{.*}} to i8* |
| 209 | // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0 |
| 210 | // CHECK-NEXT: %[[vbptr_E:.*]] = bitcast i8* %[[offs]] to [3 x i32]** |
| 211 | // CHECK-NEXT: store [3 x i32]* @"\01??_8E@constructors@@7B01@@", [3 x i32]** %[[vbptr_E]] |
| 212 | // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 4 |
| 213 | // CHECK-NEXT: %[[vbptr_C:.*]] = bitcast i8* %[[offs]] to [2 x i32]** |
| 214 | // CHECK-NEXT: store [2 x i32]* @"\01??_8E@constructors@@7BC@1@@", [2 x i32]** %[[vbptr_C]] |
Timur Iskhodzhanov | 1d4fff5 | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 215 | // CHECK-NEXT: bitcast %"struct.constructors::E"* %{{.*}} to %"struct.constructors::A"* |
| 216 | // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}}) |
| 217 | // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0) |
| 218 | // CHECK-NEXT: br label %[[SKIP_VBASES]] |
| 219 | // |
| 220 | // CHECK: [[SKIP_VBASES]] |
| 221 | // CHECK: ret |
| 222 | } |
| 223 | |
| 224 | } // end namespace constructors |
Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 225 | |
| 226 | namespace dtors { |
| 227 | |
| 228 | struct A { |
| 229 | ~A(); |
| 230 | }; |
| 231 | |
| 232 | void call_nv_complete(A *a) { |
| 233 | a->~A(); |
| 234 | // CHECK: define void @"\01?call_nv_complete@dtors@@YAXPAUA@1@@Z" |
| 235 | // CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ" |
| 236 | // CHECK: ret |
| 237 | } |
| 238 | |
| 239 | // CHECK: declare x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ" |
| 240 | |
| 241 | // Now try some virtual bases, where we need the complete dtor. |
| 242 | |
| 243 | struct B : virtual A { ~B(); }; |
| 244 | struct C : virtual A { ~C(); }; |
| 245 | struct D : B, C { ~D(); }; |
| 246 | |
| 247 | void call_vbase_complete(D *d) { |
| 248 | d->~D(); |
| 249 | // CHECK: define void @"\01?call_vbase_complete@dtors@@YAXPAUD@1@@Z" |
| 250 | // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}}) |
| 251 | // CHECK: ret |
| 252 | } |
| 253 | |
| 254 | // The complete dtor should call the base dtors for D and the vbase A (once). |
| 255 | // CHECK: define linkonce_odr x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ" |
| 256 | // CHECK-NOT: call |
| 257 | // CHECK: call x86_thiscallcc void @"\01??1D@dtors@@QAE@XZ" |
| 258 | // CHECK-NOT: call |
| 259 | // CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ" |
| 260 | // CHECK-NOT: call |
| 261 | // CHECK: ret |
| 262 | |
| 263 | void destroy_d_complete() { |
| 264 | D d; |
| 265 | // CHECK: define void @"\01?destroy_d_complete@dtors@@YAXXZ" |
| 266 | // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}}) |
| 267 | // CHECK: ret |
| 268 | } |
| 269 | |
| 270 | // FIXME: Clang manually inlines the deletion, so we don't get a call to the |
| 271 | // deleting dtor (_G). The only way to call deleting dtors currently is through |
| 272 | // a vftable. |
| 273 | void call_nv_deleting_dtor(D *d) { |
| 274 | delete d; |
| 275 | // CHECK: define void @"\01?call_nv_deleting_dtor@dtors@@YAXPAUD@1@@Z" |
| 276 | // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}}) |
| 277 | // CHECK: call void @"\01??3@YAXPAX@Z" |
| 278 | // CHECK: ret |
| 279 | } |
| 280 | |
| 281 | } |