1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=i386-pc-win32 -emit-llvm -o %t 2*f4a2713aSLionel Sambuc // RUN: FileCheck %s < %t 3*f4a2713aSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK2 %s < %t 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc // For now, just make sure x86_64 doesn't crash. 6*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=x86_64-pc-win32 -emit-llvm -o %t 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc struct VBase { 9*f4a2713aSLionel Sambuc virtual ~VBase(); 10*f4a2713aSLionel Sambuc virtual void foo(); 11*f4a2713aSLionel Sambuc virtual void bar(); 12*f4a2713aSLionel Sambuc int field; 13*f4a2713aSLionel Sambuc }; 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc struct B : virtual VBase { 16*f4a2713aSLionel Sambuc B(); 17*f4a2713aSLionel Sambuc virtual ~B(); 18*f4a2713aSLionel Sambuc virtual void foo(); 19*f4a2713aSLionel Sambuc virtual void bar(); 20*f4a2713aSLionel Sambuc }; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc B::B() { 23*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc %struct.B* @"\01??0B@@QAE@XZ" 24*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = load %struct.B** 25*f4a2713aSLionel Sambuc // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]] 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc // Don't check the INIT_VBASES case as it's covered by the ctor tests. 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc // CHECK: %[[SKIP_VBASES]] 30*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 31*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 0 32*f4a2713aSLionel Sambuc // ... 33*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 34*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 %{{.*}} 35*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VFPTR_i8]] to [3 x i8*]** 36*f4a2713aSLionel Sambuc // CHECK: store [3 x i8*]* @"\01??_7B@@6B@", [3 x i8*]** %[[VFPTR]] 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc // Initialize vtorDisp: 39*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 40*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 0 41*f4a2713aSLionel Sambuc // ... 42*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}} 43*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8 44*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 45*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 %[[VBASE_OFFSET]] 46*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8* %[[VBASE_i8]], i32 -4 47*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_PTR:.*]] = bitcast i8* %[[VTORDISP_i8]] to i32* 48*f4a2713aSLionel Sambuc // CHECK: store i32 %[[VTORDISP_VAL]], i32* %[[VTORDISP_PTR]] 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc // CHECK: ret 51*f4a2713aSLionel Sambuc } 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc B::~B() { 54*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc void @"\01??1B@@UAE@XZ" 55*f4a2713aSLionel Sambuc // Adjust the this parameter: 56*f4a2713aSLionel Sambuc // CHECK: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* 57*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8* %[[THIS_PARAM_i8]], i32 -8 58*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* 59*f4a2713aSLionel Sambuc // CHECK: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 60*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]] 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc // Restore the vfptr that could have been changed by a subclass. 63*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 64*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 0 65*f4a2713aSLionel Sambuc // ... 66*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 67*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 %{{.*}} 68*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VFPTR_i8]] to [3 x i8*]** 69*f4a2713aSLionel Sambuc // CHECK: store [3 x i8*]* @"\01??_7B@@6B@", [3 x i8*]** %[[VFPTR]] 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc // Initialize vtorDisp: 72*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 73*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 0 74*f4a2713aSLionel Sambuc // ... 75*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}} 76*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8 77*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 78*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i32 %[[VBASE_OFFSET]] 79*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8* %[[VBASE_i8]], i32 -4 80*f4a2713aSLionel Sambuc // CHECK: %[[VTORDISP_PTR:.*]] = bitcast i8* %[[VTORDISP_i8]] to i32* 81*f4a2713aSLionel Sambuc // CHECK: store i32 %[[VTORDISP_VAL]], i32* %[[VTORDISP_PTR]] 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambuc foo(); // Avoid the "trivial destructor" optimization. 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambuc // CHECK: ret 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambuc // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* 88*f4a2713aSLionel Sambuc // CHECK2: %[[THIS:.*]] = load %struct.B** {{.*}} 89*f4a2713aSLionel Sambuc // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 90*f4a2713aSLionel Sambuc // CHECK2: %[[B_i8:.*]] = getelementptr i8* %[[THIS_i8]], i32 8 91*f4a2713aSLionel Sambuc // CHECK2: %[[B:.*]] = bitcast i8* %[[B_i8]] to %struct.B* 92*f4a2713aSLionel Sambuc // CHECK2: call x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %[[B]]) 93*f4a2713aSLionel Sambuc // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 94*f4a2713aSLionel Sambuc // CHECK2: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i64 8 95*f4a2713aSLionel Sambuc // CHECK2: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase* 96*f4a2713aSLionel Sambuc // CHECK2: call x86_thiscallcc void @"\01??1VBase@@UAE@XZ"(%struct.VBase* %[[VBASE]]) 97*f4a2713aSLionel Sambuc // CHECK2: ret 98*f4a2713aSLionel Sambuc 99*f4a2713aSLionel Sambuc // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_GB@@UAEPAXI@Z" 100*f4a2713aSLionel Sambuc // CHECK2: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* 101*f4a2713aSLionel Sambuc // CHECK2: %[[THIS_i8:.*]] = getelementptr inbounds i8* %[[THIS_PARAM_i8:.*]], i32 -8 102*f4a2713aSLionel Sambuc // CHECK2: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* 103*f4a2713aSLionel Sambuc // CHECK2: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 104*f4a2713aSLionel Sambuc // CHECK2: %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]] 105*f4a2713aSLionel Sambuc // CHECK2: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[THIS]]) 106*f4a2713aSLionel Sambuc // ... 107*f4a2713aSLionel Sambuc // CHECK2: ret 108*f4a2713aSLionel Sambuc } 109*f4a2713aSLionel Sambuc 110*f4a2713aSLionel Sambuc void B::foo() { 111*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc void @"\01?foo@B@@UAEXXZ"(i8* 112*f4a2713aSLionel Sambuc // 113*f4a2713aSLionel Sambuc // B::foo gets 'this' cast to VBase* in ECX (i.e. this+8) so we 114*f4a2713aSLionel Sambuc // need to adjust 'this' before use. 115*f4a2713aSLionel Sambuc // 116*f4a2713aSLionel Sambuc // CHECK: %[[THIS_ADDR:.*]] = alloca %struct.B*, align 4 117*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8* %[[ECX:.*]], i32 -8 118*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* 119*f4a2713aSLionel Sambuc // CHECK: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR]], align 4 120*f4a2713aSLionel Sambuc 121*f4a2713aSLionel Sambuc field = 42; 122*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]] 123*f4a2713aSLionel Sambuc // CHECK: %[[THIS8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 124*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[THIS8]], i32 0 125*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** 126*f4a2713aSLionel Sambuc // CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] 127*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 128*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* 129*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] 130*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] 131*f4a2713aSLionel Sambuc // CHECK: %[[THIS8:.*]] = bitcast %struct.B* %[[THIS]] to i8* 132*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS8]], i32 %[[VBOFFSET]] 133*f4a2713aSLionel Sambuc // CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase* 134*f4a2713aSLionel Sambuc // CHECK: %[[FIELD:.*]] = getelementptr inbounds %struct.VBase* %[[VBASE]], i32 0, i32 1 135*f4a2713aSLionel Sambuc // CHECK: store i32 42, i32* %[[FIELD]], align 4 136*f4a2713aSLionel Sambuc // 137*f4a2713aSLionel Sambuc // CHECK: ret void 138*f4a2713aSLionel Sambuc } 139*f4a2713aSLionel Sambuc 140*f4a2713aSLionel Sambuc void call_vbase_bar(B *obj) { 141*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @"\01?call_vbase_bar@@YAXPAUB@@@Z"(%struct.B* %obj) 142*f4a2713aSLionel Sambuc // CHECK: %[[OBJ:.*]] = load %struct.B 143*f4a2713aSLionel Sambuc 144*f4a2713aSLionel Sambuc obj->bar(); 145*f4a2713aSLionel Sambuc // When calling a vbase's virtual method, one needs to adjust 'this' 146*f4a2713aSLionel Sambuc // at the caller site. 147*f4a2713aSLionel Sambuc // 148*f4a2713aSLionel Sambuc // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* 149*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 150*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** 151*f4a2713aSLionel Sambuc // CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] 152*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 153*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* 154*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] 155*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] 156*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] 157*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (i8*)*** 158*f4a2713aSLionel Sambuc // CHECK: %[[VFTABLE:.*]] = load void (i8*)*** %[[VFPTR]] 159*f4a2713aSLionel Sambuc // CHECK: %[[VFUN:.*]] = getelementptr inbounds void (i8*)** %[[VFTABLE]], i64 2 160*f4a2713aSLionel Sambuc // CHECK: %[[VFUN_VALUE:.*]] = load void (i8*)** %[[VFUN]] 161*f4a2713aSLionel Sambuc // 162*f4a2713aSLionel Sambuc // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* 163*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 164*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** 165*f4a2713aSLionel Sambuc // CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] 166*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 167*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* 168*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] 169*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] 170*f4a2713aSLionel Sambuc // CHECK: %[[VBASE:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] 171*f4a2713aSLionel Sambuc // 172*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](i8* %[[VBASE]]) 173*f4a2713aSLionel Sambuc // 174*f4a2713aSLionel Sambuc // CHECK: ret void 175*f4a2713aSLionel Sambuc } 176*f4a2713aSLionel Sambuc 177*f4a2713aSLionel Sambuc void delete_B(B *obj) { 178*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @"\01?delete_B@@YAXPAUB@@@Z"(%struct.B* %obj) 179*f4a2713aSLionel Sambuc // CHECK: %[[OBJ:.*]] = load %struct.B 180*f4a2713aSLionel Sambuc 181*f4a2713aSLionel Sambuc delete obj; 182*f4a2713aSLionel Sambuc // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* 183*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 184*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** 185*f4a2713aSLionel Sambuc // CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] 186*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 187*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* 188*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] 189*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] 190*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] 191*f4a2713aSLionel Sambuc // CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (%struct.B*, i32)*** 192*f4a2713aSLionel Sambuc // CHECK: %[[VFTABLE:.*]] = load void (%struct.B*, i32)*** %[[VFPTR]] 193*f4a2713aSLionel Sambuc // CHECK: %[[VFUN:.*]] = getelementptr inbounds void (%struct.B*, i32)** %[[VFTABLE]], i64 0 194*f4a2713aSLionel Sambuc // CHECK: %[[VFUN_VALUE:.*]] = load void (%struct.B*, i32)** %[[VFUN]] 195*f4a2713aSLionel Sambuc // 196*f4a2713aSLionel Sambuc // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* 197*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 198*f4a2713aSLionel Sambuc // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** 199*f4a2713aSLionel Sambuc // CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] 200*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 201*f4a2713aSLionel Sambuc // CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* 202*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] 203*f4a2713aSLionel Sambuc // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] 204*f4a2713aSLionel Sambuc // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] 205*f4a2713aSLionel Sambuc // CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.B* 206*f4a2713aSLionel Sambuc // 207*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](%struct.B* %[[VBASE]], i32 1) 208*f4a2713aSLionel Sambuc // CHECK: ret void 209*f4a2713aSLionel Sambuc } 210*f4a2713aSLionel Sambuc 211*f4a2713aSLionel Sambuc void call_complete_dtor() { 212*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @"\01?call_complete_dtor@@YAXXZ" 213*f4a2713aSLionel Sambuc B b; 214*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc %struct.B* @"\01??0B@@QAE@XZ"(%struct.B* %[[B:.*]], i32 1) 215*f4a2713aSLionel Sambuc // CHECK-NOT: getelementptr 216*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[B]]) 217*f4a2713aSLionel Sambuc // CHECK: ret 218*f4a2713aSLionel Sambuc } 219*f4a2713aSLionel Sambuc 220*f4a2713aSLionel Sambuc struct C : B { 221*f4a2713aSLionel Sambuc C(); 222*f4a2713aSLionel Sambuc // has an implicit vdtor. 223*f4a2713aSLionel Sambuc }; 224*f4a2713aSLionel Sambuc 225*f4a2713aSLionel Sambuc // Used to crash on an assertion. 226*f4a2713aSLionel Sambuc C::C() { 227*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc %struct.C* @"\01??0C@@QAE@XZ" 228*f4a2713aSLionel Sambuc } 229*f4a2713aSLionel Sambuc 230*f4a2713aSLionel Sambuc namespace multiple_vbases { 231*f4a2713aSLionel Sambuc struct A { 232*f4a2713aSLionel Sambuc virtual void a(); 233*f4a2713aSLionel Sambuc }; 234*f4a2713aSLionel Sambuc 235*f4a2713aSLionel Sambuc struct B { 236*f4a2713aSLionel Sambuc virtual void b(); 237*f4a2713aSLionel Sambuc }; 238*f4a2713aSLionel Sambuc 239*f4a2713aSLionel Sambuc struct C { 240*f4a2713aSLionel Sambuc virtual void c(); 241*f4a2713aSLionel Sambuc }; 242*f4a2713aSLionel Sambuc 243*f4a2713aSLionel Sambuc struct D : virtual A, virtual B, virtual C { 244*f4a2713aSLionel Sambuc virtual void a(); 245*f4a2713aSLionel Sambuc virtual void b(); 246*f4a2713aSLionel Sambuc virtual void c(); 247*f4a2713aSLionel Sambuc D(); 248*f4a2713aSLionel Sambuc }; 249*f4a2713aSLionel Sambuc 250*f4a2713aSLionel Sambuc D::D() { 251*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc %"struct.multiple_vbases::D"* @"\01??0D@multiple_vbases@@QAE@XZ" 252*f4a2713aSLionel Sambuc // Just make sure we emit 3 vtordisps after initializing vfptrs. 253*f4a2713aSLionel Sambuc // CHECK: store [1 x i8*]* @"\01??_7D@multiple_vbases@@6BA@1@@", [1 x i8*]** %{{.*}} 254*f4a2713aSLionel Sambuc // CHECK: store [1 x i8*]* @"\01??_7D@multiple_vbases@@6BB@1@@", [1 x i8*]** %{{.*}} 255*f4a2713aSLionel Sambuc // CHECK: store [1 x i8*]* @"\01??_7D@multiple_vbases@@6BC@1@@", [1 x i8*]** %{{.*}} 256*f4a2713aSLionel Sambuc // ... 257*f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* %{{.*}} 258*f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* %{{.*}} 259*f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* %{{.*}} 260*f4a2713aSLionel Sambuc // CHECK: ret 261*f4a2713aSLionel Sambuc } 262*f4a2713aSLionel Sambuc } 263*f4a2713aSLionel Sambuc 264*f4a2713aSLionel Sambuc namespace diamond { 265*f4a2713aSLionel Sambuc struct A { 266*f4a2713aSLionel Sambuc A(); 267*f4a2713aSLionel Sambuc virtual ~A(); 268*f4a2713aSLionel Sambuc }; 269*f4a2713aSLionel Sambuc 270*f4a2713aSLionel Sambuc struct B : virtual A { 271*f4a2713aSLionel Sambuc B(); 272*f4a2713aSLionel Sambuc ~B(); 273*f4a2713aSLionel Sambuc }; 274*f4a2713aSLionel Sambuc 275*f4a2713aSLionel Sambuc struct C : virtual A { 276*f4a2713aSLionel Sambuc C(); 277*f4a2713aSLionel Sambuc ~C(); 278*f4a2713aSLionel Sambuc int c1, c2, c3; 279*f4a2713aSLionel Sambuc }; 280*f4a2713aSLionel Sambuc 281*f4a2713aSLionel Sambuc struct Z { 282*f4a2713aSLionel Sambuc int z; 283*f4a2713aSLionel Sambuc }; 284*f4a2713aSLionel Sambuc 285*f4a2713aSLionel Sambuc struct D : virtual Z, B, C { 286*f4a2713aSLionel Sambuc D(); 287*f4a2713aSLionel Sambuc ~D(); 288*f4a2713aSLionel Sambuc } d; 289*f4a2713aSLionel Sambuc 290*f4a2713aSLionel Sambuc D::~D() { 291*f4a2713aSLionel Sambuc // CHECK-LABEL: define x86_thiscallcc void @"\01??1D@diamond@@UAE@XZ"(%"struct.diamond::D"*) 292*f4a2713aSLionel Sambuc // CHECK: %[[ARG_i8:.*]] = bitcast %"struct.diamond::D"* %{{.*}} to i8* 293*f4a2713aSLionel Sambuc // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8* %[[ARG_i8]], i32 -24 294*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %"struct.diamond::D"* 295*f4a2713aSLionel Sambuc // CHECK: store %"struct.diamond::D"* %[[THIS]], %"struct.diamond::D"** %[[THIS_VAL:.*]], align 4 296*f4a2713aSLionel Sambuc // CHECK: %[[THIS:.*]] = load %"struct.diamond::D"** %[[THIS_VAL]] 297*f4a2713aSLionel Sambuc // CHECK: %[[D_i8:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to i8* 298*f4a2713aSLionel Sambuc // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8* %[[D_i8]], i64 4 299*f4a2713aSLionel Sambuc // CHECK: %[[C:.*]] = bitcast i8* %[[C_i8]] to %"struct.diamond::C"* 300*f4a2713aSLionel Sambuc // CHECK: %[[C_i8:.*]] = bitcast %"struct.diamond::C"* %[[C]] to i8* 301*f4a2713aSLionel Sambuc // CHECK: %[[ARG_i8:.*]] = getelementptr i8* %{{.*}}, i32 16 302*f4a2713aSLionel Sambuc // FIXME: We might consider changing the dtor this parameter type to i8*. 303*f4a2713aSLionel Sambuc // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::C"* 304*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc void @"\01??1C@diamond@@UAE@XZ"(%"struct.diamond::C"* %[[ARG]]) 305*f4a2713aSLionel Sambuc 306*f4a2713aSLionel Sambuc // CHECK: %[[B:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to %"struct.diamond::B"* 307*f4a2713aSLionel Sambuc // CHECK: %[[B_i8:.*]] = bitcast %"struct.diamond::B"* %[[B]] to i8* 308*f4a2713aSLionel Sambuc // CHECK: %[[ARG_i8:.*]] = getelementptr i8* %[[B_i8]], i32 4 309*f4a2713aSLionel Sambuc // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::B"* 310*f4a2713aSLionel Sambuc // CHECK: call x86_thiscallcc void @"\01??1B@diamond@@UAE@XZ"(%"struct.diamond::B"* %[[ARG]]) 311*f4a2713aSLionel Sambuc // CHECK: ret void 312*f4a2713aSLionel Sambuc } 313*f4a2713aSLionel Sambuc 314*f4a2713aSLionel Sambuc } 315