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