Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fno-rtti -triple=i386-pc-win32 -emit-llvm -o %t |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 2 | // RUN: FileCheck %s < %t |
| 3 | // RUN: FileCheck --check-prefix=CHECK2 %s < %t |
Peter Collingbourne | 66f82e6 | 2013-06-28 20:45:28 +0000 | [diff] [blame] | 4 | |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 5 | // For now, just make sure x86_64 doesn't crash. |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 6 | // RUN: %clang_cc1 %s -fno-rtti -triple=x86_64-pc-win32 -emit-llvm -o %t |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 7 | |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 8 | struct VBase { |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 9 | virtual ~VBase(); |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 10 | virtual void foo(); |
| 11 | virtual void bar(); |
| 12 | int field; |
Peter Collingbourne | 66f82e6 | 2013-06-28 20:45:28 +0000 | [diff] [blame] | 13 | }; |
| 14 | |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 15 | struct B : virtual VBase { |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 16 | B(); |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 17 | virtual ~B(); |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 18 | virtual void foo(); |
| 19 | virtual void bar(); |
| 20 | }; |
| 21 | |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 22 | B::B() { |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 23 | // CHECK-LABEL: define x86_thiscallcc %struct.B* @"\01??0B@@QAE@XZ" |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 24 | // CHECK: %[[THIS:.*]] = load %struct.B*, %struct.B** |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 25 | // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 26 | |
| 27 | // Don't check the INIT_VBASES case as it's covered by the ctor tests. |
| 28 | |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 29 | // CHECK: %[[SKIP_VBASES]] |
| 30 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 31 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 0 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 32 | // ... |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 33 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 34 | // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 %{{.*}} |
Reid Kleckner | 8d58513 | 2014-12-03 21:00:21 +0000 | [diff] [blame] | 35 | // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VFPTR_i8]] to i32 (...)*** |
| 36 | // CHECK: store i32 (...)** bitcast ([3 x i8*]* @"\01??_7B@@6B@" to i32 (...)**), i32 (...)*** %[[VFPTR]] |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 37 | |
| 38 | // Initialize vtorDisp: |
| 39 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 40 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 0 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 41 | // ... |
| 42 | // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}} |
| 43 | // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8 |
| 44 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 45 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 %[[VBASE_OFFSET]] |
| 46 | // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8, i8* %[[VBASE_i8]], i32 -4 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 47 | // CHECK: %[[VTORDISP_PTR:.*]] = bitcast i8* %[[VTORDISP_i8]] to i32* |
| 48 | // CHECK: store i32 %[[VTORDISP_VAL]], i32* %[[VTORDISP_PTR]] |
| 49 | |
| 50 | // CHECK: ret |
| 51 | } |
| 52 | |
| 53 | B::~B() { |
| 54 | // CHECK-LABEL: define x86_thiscallcc void @"\01??1B@@UAE@XZ" |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 55 | // Adjust the this parameter: |
| 56 | // CHECK: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 57 | // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_PARAM_i8]], i32 -8 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 58 | // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* |
| 59 | // CHECK: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 60 | // CHECK: %[[THIS:.*]] = load %struct.B*, %struct.B** %[[THIS_ADDR]] |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 61 | |
| 62 | // Restore the vfptr that could have been changed by a subclass. |
| 63 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 64 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 0 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 65 | // ... |
| 66 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 67 | // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 %{{.*}} |
Reid Kleckner | 8d58513 | 2014-12-03 21:00:21 +0000 | [diff] [blame] | 68 | // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VFPTR_i8]] to i32 (...)*** |
| 69 | // CHECK: store i32 (...)** bitcast ([3 x i8*]* @"\01??_7B@@6B@" to i32 (...)**), i32 (...)*** %[[VFPTR]] |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 70 | |
| 71 | // Initialize vtorDisp: |
| 72 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 73 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 0 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 74 | // ... |
| 75 | // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}} |
| 76 | // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8 |
| 77 | // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 78 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 %[[VBASE_OFFSET]] |
| 79 | // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8, i8* %[[VBASE_i8]], i32 -4 |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 80 | // CHECK: %[[VTORDISP_PTR:.*]] = bitcast i8* %[[VTORDISP_i8]] to i32* |
| 81 | // CHECK: store i32 %[[VTORDISP_VAL]], i32* %[[VTORDISP_PTR]] |
| 82 | |
| 83 | foo(); // Avoid the "trivial destructor" optimization. |
| 84 | |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 85 | // CHECK: ret |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 86 | |
| 87 | // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 88 | // CHECK2: %[[THIS:.*]] = load %struct.B*, %struct.B** {{.*}} |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 89 | // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 90 | // CHECK2: %[[B_i8:.*]] = getelementptr i8, i8* %[[THIS_i8]], i32 8 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 91 | // CHECK2: %[[B:.*]] = bitcast i8* %[[B_i8]] to %struct.B* |
| 92 | // CHECK2: call x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %[[B]]) |
| 93 | // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 94 | // CHECK2: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_i8]], i32 8 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 95 | // CHECK2: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase* |
| 96 | // CHECK2: call x86_thiscallcc void @"\01??1VBase@@UAE@XZ"(%struct.VBase* %[[VBASE]]) |
| 97 | // CHECK2: ret |
| 98 | |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 99 | // CHECK2-LABEL: define linkonce_odr x86_thiscallcc i8* @"\01??_GB@@UAEPAXI@Z" |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 100 | // CHECK2: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 101 | // CHECK2: %[[THIS_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS_PARAM_i8:.*]], i32 -8 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 102 | // CHECK2: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* |
| 103 | // CHECK2: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 104 | // CHECK2: %[[THIS:.*]] = load %struct.B*, %struct.B** %[[THIS_ADDR]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 105 | // CHECK2: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[THIS]]) |
| 106 | // ... |
| 107 | // CHECK2: ret |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 110 | void B::foo() { |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 111 | // CHECK-LABEL: define x86_thiscallcc void @"\01?foo@B@@UAEXXZ"(i8* |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 112 | // |
| 113 | // B::foo gets 'this' cast to VBase* in ECX (i.e. this+8) so we |
| 114 | // need to adjust 'this' before use. |
| 115 | // |
| 116 | // CHECK: %[[THIS_ADDR:.*]] = alloca %struct.B*, align 4 |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 117 | // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8, i8* %[[ECX:.*]], i32 -8 |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 118 | // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* |
| 119 | // CHECK: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR]], align 4 |
| 120 | |
| 121 | field = 42; |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 122 | // CHECK: %[[THIS:.*]] = load %struct.B*, %struct.B** %[[THIS_ADDR]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 123 | // CHECK: %[[THIS8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 124 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[THIS8]], i32 0 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame] | 125 | // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 126 | // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 127 | // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 128 | // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 129 | // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] |
| 130 | // CHECK: %[[THIS8:.*]] = bitcast %struct.B* %[[THIS]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 131 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[THIS8]], i32 %[[VBOFFSET]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 132 | // CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 133 | // CHECK: %[[FIELD:.*]] = getelementptr inbounds %struct.VBase, %struct.VBase* %[[VBASE]], i32 0, i32 1 |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 134 | // CHECK: store i32 42, i32* %[[FIELD]], align 4 |
| 135 | // |
| 136 | // CHECK: ret void |
| 137 | } |
| 138 | |
| 139 | void call_vbase_bar(B *obj) { |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 140 | // CHECK-LABEL: define void @"\01?call_vbase_bar@@YAXPAUB@@@Z"(%struct.B* %obj) |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 141 | // CHECK: %[[OBJ:.*]] = load %struct.B |
| 142 | |
| 143 | obj->bar(); |
| 144 | // When calling a vbase's virtual method, one needs to adjust 'this' |
| 145 | // at the caller site. |
| 146 | // |
| 147 | // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 148 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 0 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame] | 149 | // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 150 | // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 151 | // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 152 | // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 153 | // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 154 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 155 | // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (i8*)*** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 156 | // CHECK: %[[VFTABLE:.*]] = load void (i8*)**, void (i8*)*** %[[VFPTR]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 157 | // CHECK: %[[VFUN:.*]] = getelementptr inbounds void (i8*)*, void (i8*)** %[[VFTABLE]], i64 2 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 158 | // CHECK: %[[VFUN_VALUE:.*]] = load void (i8*)*, void (i8*)** %[[VFUN]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 159 | // |
| 160 | // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 161 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 0 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame] | 162 | // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 163 | // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 164 | // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 165 | // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 166 | // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 167 | // CHECK: %[[VBASE:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 168 | // |
| 169 | // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](i8* %[[VBASE]]) |
| 170 | // |
| 171 | // CHECK: ret void |
| 172 | } |
Timur Iskhodzhanov | ad9d3b8 | 2013-10-09 09:23:58 +0000 | [diff] [blame] | 173 | |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 174 | void delete_B(B *obj) { |
| 175 | // CHECK-LABEL: define void @"\01?delete_B@@YAXPAUB@@@Z"(%struct.B* %obj) |
| 176 | // CHECK: %[[OBJ:.*]] = load %struct.B |
| 177 | |
| 178 | delete obj; |
| 179 | // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 180 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 0 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame] | 181 | // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 182 | // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 183 | // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 184 | // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 185 | // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 186 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 187 | // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to i8* (%struct.B*, i32)*** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 188 | // CHECK: %[[VFTABLE:.*]] = load i8* (%struct.B*, i32)**, i8* (%struct.B*, i32)*** %[[VFPTR]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 189 | // CHECK: %[[VFUN:.*]] = getelementptr inbounds i8* (%struct.B*, i32)*, i8* (%struct.B*, i32)** %[[VFTABLE]], i64 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 190 | // CHECK: %[[VFUN_VALUE:.*]] = load i8* (%struct.B*, i32)*, i8* (%struct.B*, i32)** %[[VFUN]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 191 | // |
| 192 | // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 193 | // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 0 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame] | 194 | // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 195 | // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 196 | // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 197 | // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 198 | // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 199 | // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 200 | // CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.B* |
| 201 | // |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 202 | // CHECK: call x86_thiscallcc i8* %[[VFUN_VALUE]](%struct.B* %[[VBASE]], i32 1) |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 203 | // CHECK: ret void |
| 204 | } |
| 205 | |
| 206 | void call_complete_dtor() { |
| 207 | // CHECK-LABEL: define void @"\01?call_complete_dtor@@YAXXZ" |
| 208 | B b; |
| 209 | // CHECK: call x86_thiscallcc %struct.B* @"\01??0B@@QAE@XZ"(%struct.B* %[[B:.*]], i32 1) |
| 210 | // CHECK-NOT: getelementptr |
| 211 | // CHECK: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[B]]) |
| 212 | // CHECK: ret |
| 213 | } |
| 214 | |
Timur Iskhodzhanov | a895758 | 2014-03-07 09:34:59 +0000 | [diff] [blame] | 215 | struct C : B { |
Timur Iskhodzhanov | ad9d3b8 | 2013-10-09 09:23:58 +0000 | [diff] [blame] | 216 | C(); |
| 217 | // has an implicit vdtor. |
| 218 | }; |
| 219 | |
| 220 | // Used to crash on an assertion. |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 221 | C::C() { |
| 222 | // CHECK-LABEL: define x86_thiscallcc %struct.C* @"\01??0C@@QAE@XZ" |
| 223 | } |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 224 | |
| 225 | namespace multiple_vbases { |
| 226 | struct A { |
| 227 | virtual void a(); |
| 228 | }; |
| 229 | |
| 230 | struct B { |
| 231 | virtual void b(); |
| 232 | }; |
| 233 | |
| 234 | struct C { |
| 235 | virtual void c(); |
| 236 | }; |
| 237 | |
| 238 | struct D : virtual A, virtual B, virtual C { |
| 239 | virtual void a(); |
| 240 | virtual void b(); |
| 241 | virtual void c(); |
| 242 | D(); |
| 243 | }; |
| 244 | |
| 245 | D::D() { |
| 246 | // CHECK-LABEL: define x86_thiscallcc %"struct.multiple_vbases::D"* @"\01??0D@multiple_vbases@@QAE@XZ" |
| 247 | // Just make sure we emit 3 vtordisps after initializing vfptrs. |
Reid Kleckner | 8d58513 | 2014-12-03 21:00:21 +0000 | [diff] [blame] | 248 | // CHECK: store i32 (...)** bitcast ([1 x i8*]* @"\01??_7D@multiple_vbases@@6BA@1@@" to i32 (...)**), i32 (...)*** %{{.*}} |
| 249 | // CHECK: store i32 (...)** bitcast ([1 x i8*]* @"\01??_7D@multiple_vbases@@6BB@1@@" to i32 (...)**), i32 (...)*** %{{.*}} |
| 250 | // CHECK: store i32 (...)** bitcast ([1 x i8*]* @"\01??_7D@multiple_vbases@@6BC@1@@" to i32 (...)**), i32 (...)*** %{{.*}} |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 251 | // ... |
| 252 | // CHECK: store i32 %{{.*}}, i32* %{{.*}} |
| 253 | // CHECK: store i32 %{{.*}}, i32* %{{.*}} |
| 254 | // CHECK: store i32 %{{.*}}, i32* %{{.*}} |
| 255 | // CHECK: ret |
| 256 | } |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | namespace diamond { |
| 260 | struct A { |
| 261 | A(); |
| 262 | virtual ~A(); |
| 263 | }; |
| 264 | |
| 265 | struct B : virtual A { |
| 266 | B(); |
| 267 | ~B(); |
| 268 | }; |
| 269 | |
| 270 | struct C : virtual A { |
| 271 | C(); |
| 272 | ~C(); |
| 273 | int c1, c2, c3; |
| 274 | }; |
| 275 | |
| 276 | struct Z { |
| 277 | int z; |
| 278 | }; |
| 279 | |
| 280 | struct D : virtual Z, B, C { |
| 281 | D(); |
| 282 | ~D(); |
| 283 | } d; |
| 284 | |
| 285 | D::~D() { |
| 286 | // CHECK-LABEL: define x86_thiscallcc void @"\01??1D@diamond@@UAE@XZ"(%"struct.diamond::D"*) |
| 287 | // CHECK: %[[ARG_i8:.*]] = bitcast %"struct.diamond::D"* %{{.*}} to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 288 | // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8, i8* %[[ARG_i8]], i32 -24 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 289 | // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %"struct.diamond::D"* |
| 290 | // CHECK: store %"struct.diamond::D"* %[[THIS]], %"struct.diamond::D"** %[[THIS_VAL:.*]], align 4 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 291 | // CHECK: %[[THIS:.*]] = load %"struct.diamond::D"*, %"struct.diamond::D"** %[[THIS_VAL]] |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 292 | // CHECK: %[[D_i8:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to i8* |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 293 | // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8, i8* %[[D_i8]], i32 4 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 294 | // CHECK: %[[C:.*]] = bitcast i8* %[[C_i8]] to %"struct.diamond::C"* |
| 295 | // CHECK: %[[C_i8:.*]] = bitcast %"struct.diamond::C"* %[[C]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 296 | // CHECK: %[[ARG_i8:.*]] = getelementptr i8, i8* %{{.*}}, i32 16 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 297 | // FIXME: We might consider changing the dtor this parameter type to i8*. |
| 298 | // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::C"* |
| 299 | // CHECK: call x86_thiscallcc void @"\01??1C@diamond@@UAE@XZ"(%"struct.diamond::C"* %[[ARG]]) |
| 300 | |
| 301 | // CHECK: %[[B:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to %"struct.diamond::B"* |
| 302 | // CHECK: %[[B_i8:.*]] = bitcast %"struct.diamond::B"* %[[B]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 303 | // CHECK: %[[ARG_i8:.*]] = getelementptr i8, i8* %[[B_i8]], i32 4 |
Timur Iskhodzhanov | 62082b7 | 2013-10-16 18:24:06 +0000 | [diff] [blame] | 304 | // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::B"* |
| 305 | // CHECK: call x86_thiscallcc void @"\01??1B@diamond@@UAE@XZ"(%"struct.diamond::B"* %[[ARG]]) |
| 306 | // CHECK: ret void |
| 307 | } |
Timur Iskhodzhanov | b648732 | 2013-10-09 18:16:58 +0000 | [diff] [blame] | 308 | |
| 309 | } |
Reid Kleckner | 340ad86 | 2014-01-13 22:57:31 +0000 | [diff] [blame] | 310 | |
| 311 | namespace test2 { |
| 312 | struct A { A(); }; |
| 313 | struct B : virtual A { B() {} }; |
| 314 | struct C : B, A { C() {} }; |
| 315 | |
| 316 | // PR18435: Order mattered here. We were generating code for the delegating |
| 317 | // call to B() from C(). |
| 318 | void callC() { C x; } |
| 319 | |
| 320 | // CHECK-LABEL: define linkonce_odr x86_thiscallcc %"struct.test2::C"* @"\01??0C@test2@@QAE@XZ" |
| 321 | // CHECK: (%"struct.test2::C"* returned %this, i32 %is_most_derived) |
| 322 | // CHECK: br i1 |
| 323 | // Virtual bases |
| 324 | // CHECK: call x86_thiscallcc %"struct.test2::A"* @"\01??0A@test2@@QAE@XZ"(%"struct.test2::A"* %{{.*}}) |
| 325 | // CHECK: br label |
| 326 | // Non-virtual bases |
| 327 | // CHECK: call x86_thiscallcc %"struct.test2::B"* @"\01??0B@test2@@QAE@XZ"(%"struct.test2::B"* %{{.*}}, i32 0) |
| 328 | // CHECK: call x86_thiscallcc %"struct.test2::A"* @"\01??0A@test2@@QAE@XZ"(%"struct.test2::A"* %{{.*}}) |
| 329 | // CHECK: ret |
| 330 | |
| 331 | // CHECK2-LABEL: define linkonce_odr x86_thiscallcc %"struct.test2::B"* @"\01??0B@test2@@QAE@XZ" |
| 332 | // CHECK2: (%"struct.test2::B"* returned %this, i32 %is_most_derived) |
| 333 | // CHECK2: call x86_thiscallcc %"struct.test2::A"* @"\01??0A@test2@@QAE@XZ"(%"struct.test2::A"* %{{.*}}) |
| 334 | // CHECK2: ret |
| 335 | |
| 336 | } |
Timur Iskhodzhanov | f174942 | 2014-03-14 17:43:37 +0000 | [diff] [blame] | 337 | |
| 338 | namespace test3 { |
| 339 | // PR19104: A non-virtual call of a virtual method doesn't use vftable thunks, |
| 340 | // so requires only static adjustment which is different to the one used |
| 341 | // for virtual calls. |
| 342 | struct A { |
| 343 | virtual void foo(); |
| 344 | }; |
| 345 | |
| 346 | struct B : virtual A { |
| 347 | virtual void bar(); |
| 348 | }; |
| 349 | |
| 350 | struct C : virtual A { |
| 351 | virtual void foo(); |
| 352 | }; |
| 353 | |
| 354 | struct D : B, C { |
| 355 | virtual void bar(); |
| 356 | int field; // Laid out between C and A subobjects in D. |
| 357 | }; |
| 358 | |
| 359 | void D::bar() { |
| 360 | // CHECK-LABEL: define x86_thiscallcc void @"\01?bar@D@test3@@UAEXXZ"(%"struct.test3::D"* %this) |
| 361 | |
| 362 | C::foo(); |
| 363 | // Shouldn't need any vbtable lookups. All we have to do is adjust to C*, |
| 364 | // then compensate for the adjustment performed in the C::foo() prologue. |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 365 | // CHECK-NOT: load i8*, i8** |
Timur Iskhodzhanov | f174942 | 2014-03-14 17:43:37 +0000 | [diff] [blame] | 366 | // CHECK: %[[OBJ_i8:.*]] = bitcast %"struct.test3::D"* %{{.*}} to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 367 | // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 8 |
Timur Iskhodzhanov | f174942 | 2014-03-14 17:43:37 +0000 | [diff] [blame] | 368 | // CHECK: %[[C:.*]] = bitcast i8* %[[C_i8]] to %"struct.test3::C"* |
| 369 | // CHECK: %[[C_i8:.*]] = bitcast %"struct.test3::C"* %[[C]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 370 | // CHECK: %[[ARG:.*]] = getelementptr i8, i8* %[[C_i8]], i32 4 |
Timur Iskhodzhanov | f174942 | 2014-03-14 17:43:37 +0000 | [diff] [blame] | 371 | // CHECK: call x86_thiscallcc void @"\01?foo@C@test3@@UAEXXZ"(i8* %[[ARG]]) |
| 372 | // CHECK: ret |
| 373 | } |
| 374 | } |
Timur Iskhodzhanov | ba55702 | 2014-03-20 20:38:34 +0000 | [diff] [blame] | 375 | |
| 376 | namespace test4{ |
| 377 | // PR19172: We used to merge method vftable locations wrong. |
| 378 | |
| 379 | struct A { |
| 380 | virtual ~A() {} |
| 381 | }; |
| 382 | |
| 383 | struct B { |
| 384 | virtual ~B() {} |
| 385 | }; |
| 386 | |
| 387 | struct C : virtual A, B { |
| 388 | virtual ~C(); |
| 389 | }; |
| 390 | |
| 391 | void foo(void*); |
| 392 | |
| 393 | C::~C() { |
| 394 | // CHECK-LABEL: define x86_thiscallcc void @"\01??1C@test4@@UAE@XZ"(%"struct.test4::C"* %this) |
| 395 | |
| 396 | // In this case "this" points to the most derived class, so no GEPs needed. |
| 397 | // CHECK-NOT: getelementptr |
| 398 | // CHECK-NOT: bitcast |
Reid Kleckner | 8d58513 | 2014-12-03 21:00:21 +0000 | [diff] [blame] | 399 | // CHECK: %[[VFPTR_i8:.*]] = bitcast %"struct.test4::C"* %{{.*}} to i32 (...)*** |
| 400 | // CHECK: store i32 (...)** bitcast ([1 x i8*]* @"\01??_7C@test4@@6BB@1@@" to i32 (...)**), i32 (...)*** %[[VFPTR_i8]] |
Timur Iskhodzhanov | ba55702 | 2014-03-20 20:38:34 +0000 | [diff] [blame] | 401 | |
| 402 | foo(this); |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 403 | // CHECK: ret |
Timur Iskhodzhanov | ba55702 | 2014-03-20 20:38:34 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void destroy(C *obj) { |
| 407 | // CHECK-LABEL: define void @"\01?destroy@test4@@YAXPAUC@1@@Z"(%"struct.test4::C"* %obj) |
| 408 | |
| 409 | delete obj; |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 410 | // CHECK: %[[VPTR:.*]] = bitcast %"struct.test4::C"* %[[OBJ:.*]] to i8* (%"struct.test4::C"*, i32)*** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 411 | // CHECK: %[[VFTABLE:.*]] = load i8* (%"struct.test4::C"*, i32)**, i8* (%"struct.test4::C"*, i32)*** %[[VPTR]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 412 | // CHECK: %[[VFTENTRY:.*]] = getelementptr inbounds i8* (%"struct.test4::C"*, i32)*, i8* (%"struct.test4::C"*, i32)** %[[VFTABLE]], i64 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 413 | // CHECK: %[[VFUN:.*]] = load i8* (%"struct.test4::C"*, i32)*, i8* (%"struct.test4::C"*, i32)** %[[VFTENTRY]] |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 414 | // CHECK: call x86_thiscallcc i8* %[[VFUN]](%"struct.test4::C"* %[[OBJ]], i32 1) |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 415 | // CHECK: ret |
| 416 | } |
| 417 | |
| 418 | struct D { |
| 419 | virtual void d(); |
| 420 | }; |
| 421 | |
| 422 | // The first non-virtual base doesn't have a vdtor, |
| 423 | // but "this adjustment" is not needed. |
| 424 | struct E : D, B, virtual A { |
| 425 | virtual ~E(); |
| 426 | }; |
| 427 | |
| 428 | E::~E() { |
| 429 | // CHECK-LABEL: define x86_thiscallcc void @"\01??1E@test4@@UAE@XZ"(%"struct.test4::E"* %this) |
| 430 | |
| 431 | // In this case "this" points to the most derived class, so no GEPs needed. |
| 432 | // CHECK-NOT: getelementptr |
| 433 | // CHECK-NOT: bitcast |
Reid Kleckner | 8d58513 | 2014-12-03 21:00:21 +0000 | [diff] [blame] | 434 | // CHECK: %[[VFPTR_i8:.*]] = bitcast %"struct.test4::E"* %{{.*}} to i32 (...)*** |
| 435 | // CHECK: store i32 (...)** bitcast ([1 x i8*]* @"\01??_7E@test4@@6BD@1@@" to i32 (...)**), i32 (...)*** %[[VFPTR_i8]] |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 436 | foo(this); |
| 437 | } |
| 438 | |
| 439 | void destroy(E *obj) { |
| 440 | // CHECK-LABEL: define void @"\01?destroy@test4@@YAXPAUE@1@@Z"(%"struct.test4::E"* %obj) |
| 441 | |
| 442 | // CHECK-NOT: getelementptr |
| 443 | // CHECK: %[[OBJ_i8:.*]] = bitcast %"struct.test4::E"* %[[OBJ:.*]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 444 | // CHECK: %[[B_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 4 |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 445 | // CHECK: %[[VPTR:.*]] = bitcast i8* %[[B_i8]] to i8* (%"struct.test4::E"*, i32)*** |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 446 | // CHECK: %[[VFTABLE:.*]] = load i8* (%"struct.test4::E"*, i32)**, i8* (%"struct.test4::E"*, i32)*** %[[VPTR]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 447 | // CHECK: %[[VFTENTRY:.*]] = getelementptr inbounds i8* (%"struct.test4::E"*, i32)*, i8* (%"struct.test4::E"*, i32)** %[[VFTABLE]], i64 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 448 | // CHECK: %[[VFUN:.*]] = load i8* (%"struct.test4::E"*, i32)*, i8* (%"struct.test4::E"*, i32)** %[[VFTENTRY]] |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 449 | // CHECK: %[[OBJ_i8:.*]] = bitcast %"struct.test4::E"* %[[OBJ]] to i8* |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 450 | // CHECK: %[[B_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 4 |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 451 | // FIXME: in fact, the call should take i8* and the bitcast is redundant. |
| 452 | // CHECK: %[[B_as_E:.*]] = bitcast i8* %[[B_i8]] to %"struct.test4::E"* |
David Majnemer | 0c0b6d9 | 2014-10-31 20:09:12 +0000 | [diff] [blame] | 453 | // CHECK: call x86_thiscallcc i8* %[[VFUN]](%"struct.test4::E"* %[[B_as_E]], i32 1) |
Timur Iskhodzhanov | 67c9693 | 2014-03-21 11:07:24 +0000 | [diff] [blame] | 454 | delete obj; |
Timur Iskhodzhanov | ba55702 | 2014-03-20 20:38:34 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | } |
David Majnemer | 8671c6e | 2015-11-02 09:01:44 +0000 | [diff] [blame] | 458 | |
| 459 | namespace test5 { |
| 460 | // PR25370: Don't zero-initialize vbptrs in virtual bases. |
| 461 | struct A { |
| 462 | virtual void f(); |
| 463 | }; |
| 464 | |
| 465 | struct B : virtual A { |
| 466 | int Field; |
| 467 | }; |
| 468 | |
| 469 | struct C : B { |
| 470 | C(); |
| 471 | }; |
| 472 | |
| 473 | C::C() : B() {} |
| 474 | // CHECK-LABEL: define x86_thiscallcc %"struct.test5::C"* @"\01??0C@test5@@QAE@XZ"( |
| 475 | // CHECK: %[[THIS:.*]] = load %"struct.test5::C"*, %"struct.test5::C"** |
| 476 | // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] |
| 477 | |
| 478 | // CHECK: %[[SKIP_VBASES]] |
| 479 | // CHECK: %[[B:.*]] = bitcast %"struct.test5::C"* %[[THIS]] to %"struct.test5::B"* |
| 480 | // CHECK: %[[B_i8:.*]] = bitcast %"struct.test5::B"* %[[B]] to i8* |
| 481 | // CHECK: %[[FIELD:.*]] = getelementptr inbounds i8, i8* %[[B_i8]], i32 4 |
Pete Cooper | 3b39e88 | 2015-11-19 05:55:59 +0000 | [diff] [blame] | 482 | // CHECK: call void @llvm.memset.p0i8.i32(i8* %[[FIELD]], i8 0, i32 4, i32 4, i1 false) |
David Majnemer | 8671c6e | 2015-11-02 09:01:44 +0000 | [diff] [blame] | 483 | } |