diff options
Diffstat (limited to 'clang/test')
4 files changed, 330 insertions, 3 deletions
diff --git a/clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp b/clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp index 5d73536c2de..dc479f4eff8 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp @@ -181,3 +181,21 @@ void emit_ctors() { // CHECK: store [1 x i8*]* @"\01??_7GrandchildOverride@@6BRight@@@", [1 x i8*]** %[[VFPTR]] // CHECK: ret } + +struct LeftWithNonVirtualDtor { + virtual void left(); + ~LeftWithNonVirtualDtor(); +}; + +struct AsymmetricChild : LeftWithNonVirtualDtor, Right { + virtual ~AsymmetricChild(); +}; + +void call_asymmetric_child_complete_dtor() { + // CHECK-LABEL: define void @"\01?call_asymmetric_child_complete_dtor@@YAXXZ" + AsymmetricChild obj; + // CHECK: call x86_thiscallcc %struct.AsymmetricChild* @"\01??0AsymmetricChild@@QAE@XZ"(%struct.AsymmetricChild* %[[OBJ:.*]]) + // CHECK-NOT: getelementptr + // CHECK: call x86_thiscallcc void @"\01??1AsymmetricChild@@UAE@XZ"(%struct.AsymmetricChild* %[[OBJ]]) + // CHECK: ret +} diff --git a/clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp b/clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp index b738aba80b1..36885e88849 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=i386-pc-win32 -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=i386-pc-win32 -emit-llvm -o %t +// RUN: FileCheck %s < %t +// RUN: FileCheck --check-prefix=CHECK2 %s < %t // For now, just make sure x86_64 doesn't crash. // RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=x86_64-pc-win32 -emit-llvm -o %t @@ -50,7 +52,12 @@ B::B() { B::~B() { // CHECK-LABEL: define x86_thiscallcc void @"\01??1B@@UAE@XZ" - // CHECK: %[[THIS:.*]] = load %struct.B** + // Adjust the this parameter: + // CHECK: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* + // CHECK: %[[THIS_i8:.*]] = getelementptr i8* %[[THIS_PARAM_i8]], i64 -8 + // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* + // CHECK: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 + // CHECK: %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]] // Restore the vfptr that could have been changed by a subclass. // CHECK: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* @@ -76,6 +83,28 @@ B::~B() { foo(); // Avoid the "trivial destructor" optimization. // CHECK: ret + + // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* + // CHECK2: %[[THIS:.*]] = load %struct.B** {{.*}} + // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* + // CHECK2: %[[B_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i64 8 + // CHECK2: %[[B:.*]] = bitcast i8* %[[B_i8]] to %struct.B* + // CHECK2: call x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %[[B]]) + // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8* + // CHECK2: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i64 8 + // CHECK2: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase* + // CHECK2: call x86_thiscallcc void @"\01??1VBase@@UAE@XZ"(%struct.VBase* %[[VBASE]]) + // CHECK2: ret + + // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_GB@@UAEPAXI@Z" + // CHECK2: %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8* + // CHECK2: %[[THIS_i8:.*]] = getelementptr i8* %[[THIS_PARAM_i8:.*]], i64 -8 + // CHECK2: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B* + // CHECK2: store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4 + // CHECK2: %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]] + // CHECK2: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[THIS]]) + // ... + // CHECK2: ret } void B::foo() { @@ -145,13 +174,58 @@ void call_vbase_bar(B *obj) { // CHECK: ret void } +void delete_B(B *obj) { +// CHECK-LABEL: define void @"\01?delete_B@@YAXPAUB@@@Z"(%struct.B* %obj) +// CHECK: %[[OBJ:.*]] = load %struct.B + + delete obj; +// CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* +// CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 +// CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** +// CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] +// CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 +// CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* +// CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] +// CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] +// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] +// CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (%struct.B*, i32)*** +// CHECK: %[[VFTABLE:.*]] = load void (%struct.B*, i32)*** %[[VFPTR]] +// CHECK: %[[VFUN:.*]] = getelementptr inbounds void (%struct.B*, i32)** %[[VFTABLE]], i64 0 +// CHECK: %[[VFUN_VALUE:.*]] = load void (%struct.B*, i32)** %[[VFUN]] +// +// CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8* +// CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0 +// CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8** +// CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]] +// CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4 +// CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32* +// CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]] +// CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]] +// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]] +// CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.B* +// +// CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](%struct.B* %[[VBASE]], i32 1) +// CHECK: ret void +} + +void call_complete_dtor() { + // CHECK-LABEL: define void @"\01?call_complete_dtor@@YAXXZ" + B b; + // CHECK: call x86_thiscallcc %struct.B* @"\01??0B@@QAE@XZ"(%struct.B* %[[B:.*]], i32 1) + // CHECK-NOT: getelementptr + // CHECK: call x86_thiscallcc void @"\01??_DB@@UAE@XZ"(%struct.B* %[[B]]) + // CHECK: ret +} + struct C : B { C(); // has an implicit vdtor. }; // Used to crash on an assertion. -C::C() {} +C::C() { +// CHECK-LABEL: define x86_thiscallcc %struct.C* @"\01??0C@@QAE@XZ" +} namespace multiple_vbases { struct A { @@ -185,5 +259,56 @@ D::D() { // CHECK: store i32 %{{.*}}, i32* %{{.*}} // CHECK: ret } +} + +namespace diamond { +struct A { + A(); + virtual ~A(); +}; + +struct B : virtual A { + B(); + ~B(); +}; + +struct C : virtual A { + C(); + ~C(); + int c1, c2, c3; +}; + +struct Z { + int z; +}; + +struct D : virtual Z, B, C { + D(); + ~D(); +} d; + +D::~D() { + // CHECK-LABEL: define x86_thiscallcc void @"\01??1D@diamond@@UAE@XZ"(%"struct.diamond::D"*) + // CHECK: %[[ARG_i8:.*]] = bitcast %"struct.diamond::D"* %{{.*}} to i8* + // CHECK: %[[THIS_i8:.*]] = getelementptr i8* %[[ARG_i8]], i64 -24 + // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %"struct.diamond::D"* + // CHECK: store %"struct.diamond::D"* %[[THIS]], %"struct.diamond::D"** %[[THIS_VAL:.*]], align 4 + // CHECK: %[[THIS:.*]] = load %"struct.diamond::D"** %[[THIS_VAL]] + // CHECK: %[[D_i8:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to i8* + // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8* %[[D_i8]], i64 4 + // CHECK: %[[C:.*]] = bitcast i8* %[[C_i8]] to %"struct.diamond::C"* + // CHECK: %[[C_i8:.*]] = bitcast %"struct.diamond::C"* %[[C]] to i8* + // CHECK: %[[ARG_i8:.*]] = getelementptr inbounds i8* %{{.*}}, i64 16 + // FIXME: We might consider changing the dtor this parameter type to i8*. + // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::C"* + // CHECK: call x86_thiscallcc void @"\01??1C@diamond@@UAE@XZ"(%"struct.diamond::C"* %[[ARG]]) + + // CHECK: %[[B:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to %"struct.diamond::B"* + // CHECK: %[[B_i8:.*]] = bitcast %"struct.diamond::B"* %[[B]] to i8* + // CHECK: %[[ARG_i8:.*]] = getelementptr inbounds i8* %[[B_i8]], i64 4 + // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::B"* + // CHECK: call x86_thiscallcc void @"\01??1B@diamond@@UAE@XZ"(%"struct.diamond::B"* %[[ARG]]) + // CHECK: ret void +} } diff --git a/clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp b/clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp index 8dad4dd7794..11f5654e021 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp @@ -13,6 +13,10 @@ // RUN: FileCheck --check-prefix=THIS-THUNKS-Test1 %s < %t // RUN: FileCheck --check-prefix=THIS-THUNKS-Test2 %s < %t // RUN: FileCheck --check-prefix=THIS-THUNKS-Test3 %s < %t +// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test3 %s < %t +// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test5 %s < %t +// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test6 %s < %t +// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test7 %s < %t // RUN: FileCheck --check-prefix=RET-THUNKS-Test1 %s < %t // RUN: FileCheck --check-prefix=RET-THUNKS-Test2 %s < %t // RUN: FileCheck --check-prefix=RET-THUNKS-Test3 %s < %t @@ -349,6 +353,101 @@ struct Test3: no_thunks::Test1, no_thunks::Test2 { Test3 t3; } +namespace vdtor { +struct Test1 { + virtual ~Test1(); + virtual void z1(); +}; + +struct Test2 { + virtual ~Test2(); +}; + +struct Test3 : Test1, Test2 { + // VDTOR-THUNKS-Test3: VFTable for 'vdtor::Test1' in 'vdtor::Test3' (2 entries). + // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting] + // VDTOR-THUNKS-Test3-NEXT: 1 | void vdtor::Test1::z1() + + // VDTOR-THUNKS-Test3: VFTable for 'vdtor::Test2' in 'vdtor::Test3' (1 entries). + // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting] + // VDTOR-THUNKS-Test3-NEXT: [this adjustment: -4 non-virtual] + + // VDTOR-THUNKS-Test3: Thunks for 'vdtor::Test3::~Test3()' (1 entry). + // VDTOR-THUNKS-Test3-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTOR-THUNKS-Test3: VFTable indices for 'vdtor::Test3' (1 entries). + // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting] + virtual ~Test3(); +}; + +Test3 t3; + +struct Test4 { + // No virtual destructor here! + virtual void z4(); +}; + +struct Test5 : Test4, Test2 { + // Implicit virtual dtor here! + + // VDTOR-THUNKS-Test5: VFTable for 'vdtor::Test4' in 'vdtor::Test5' (1 entries). + // VDTOR-THUNKS-Test5-NEXT: 0 | void vdtor::Test4::z4() + + // VDTOR-THUNKS-Test5: VFTable for 'vdtor::Test2' in 'vdtor::Test5' (1 entries). + // VDTOR-THUNKS-Test5-NEXT: 0 | vdtor::Test5::~Test5() [scalar deleting] + // VDTOR-THUNKS-Test5-NEXT: [this adjustment: -4 non-virtual] + + // VDTOR-THUNKS-Test5: Thunks for 'vdtor::Test5::~Test5()' (1 entry). + // VDTOR-THUNKS-Test5-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTOR-THUNKS-Test5: VFTable indices for 'vdtor::Test5' (1 entries). + // VDTOR-THUNKS-Test5-NEXT: -- accessible via vfptr at offset 4 -- + // VDTOR-THUNKS-Test5-NEXT: 0 | vdtor::Test5::~Test5() [scalar deleting] +}; + +Test5 t5; + +struct Test6 : Test4, Test2 { + // Implicit virtual dtor here! + + // VDTOR-THUNKS-Test6: VFTable for 'vdtor::Test4' in 'vdtor::Test6' (1 entries). + // VDTOR-THUNKS-Test6-NEXT: 0 | void vdtor::Test4::z4() + + // VDTOR-THUNKS-Test6: VFTable for 'vdtor::Test2' in 'vdtor::Test6' (1 entries). + // VDTOR-THUNKS-Test6-NEXT: 0 | vdtor::Test6::~Test6() [scalar deleting] + // VDTOR-THUNKS-Test6-NEXT: [this adjustment: -4 non-virtual] + + // VDTOR-THUNKS-Test6: Thunks for 'vdtor::Test6::~Test6()' (1 entry). + // VDTOR-THUNKS-Test6-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTOR-THUNKS-Test6: VFTable indices for 'vdtor::Test6' (1 entries). + // VDTOR-THUNKS-Test6-NEXT: -- accessible via vfptr at offset 4 -- + // VDTOR-THUNKS-Test6-NEXT: 0 | vdtor::Test6::~Test6() [scalar deleting] +}; + +Test6 t6; + +struct Test7 : Test5 { + // VDTOR-THUNKS-Test7: VFTable for 'vdtor::Test4' in 'vdtor::Test5' in 'vdtor::Test7' (1 entries). + // VDTOR-THUNKS-Test7-NEXT: 0 | void vdtor::Test4::z4() + + // VDTOR-THUNKS-Test7: VFTable for 'vdtor::Test2' in 'vdtor::Test5' in 'vdtor::Test7' (1 entries). + // VDTOR-THUNKS-Test7-NEXT: 0 | vdtor::Test7::~Test7() [scalar deleting] + // VDTOR-THUNKS-Test7-NEXT: [this adjustment: -4 non-virtual] + + // VDTOR-THUNKS-Test7: Thunks for 'vdtor::Test7::~Test7()' (1 entry). + // VDTOR-THUNKS-Test7-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTOR-THUNKS-Test7: VFTable indices for 'vdtor::Test7' (1 entries). + // VDTOR-THUNKS-Test7-NEXT: -- accessible via vfptr at offset 4 -- + // VDTOR-THUNKS-Test7-NEXT: 0 | vdtor::Test7::~Test7() [scalar deleting] + virtual ~Test7(); +}; + +Test7 t7; + +} + namespace return_adjustment { struct Ret1 { diff --git a/clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp b/clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp index a7ddd37d6f8..a1fe5533b56 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp @@ -15,6 +15,10 @@ // RUN: FileCheck --check-prefix=TEST9-W %s < %t // RUN: FileCheck --check-prefix=TEST9-T %s < %t // RUN: FileCheck --check-prefix=TEST10 %s < %t +// RUN: FileCheck --check-prefix=VDTORS-Y %s < %t +// RUN: FileCheck --check-prefix=VDTORS-U %s < %t +// RUN: FileCheck --check-prefix=VDTORS-V %s < %t +// RUN: FileCheck --check-prefix=VDTORS-P %s < %t // RUN: FileCheck --check-prefix=RET-W %s < %t // RUN: FileCheck --check-prefix=RET-T %s < %t @@ -408,6 +412,87 @@ void X::f() {} X x; } +namespace vdtors { +struct X { + virtual ~X(); + virtual void zzz(); +}; + +struct Y : virtual X { + // VDTORS-Y: VFTable for 'vdtors::X' in 'vdtors::Y' (2 entries). + // VDTORS-Y-NEXT: 0 | vdtors::Y::~Y() [scalar deleting] + // VDTORS-Y-NEXT: 1 | void vdtors::X::zzz() + + // VDTORS-Y-NOT: Thunks for 'vdtors::Y::~Y()' + virtual ~Y(); +}; + +Y y; + +struct Z { + virtual void z(); +}; + +struct W : Z, X { + // Implicit virtual dtor. +}; + +struct U : virtual W { + // VDTORS-U: VFTable for 'vdtors::Z' in 'vdtors::W' in 'vdtors::U' (1 entries). + // VDTORS-U-NEXT: 0 | void vdtors::Z::z() + + // VDTORS-U: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::U' (2 entries). + // VDTORS-U-NEXT: 0 | vdtors::U::~U() [scalar deleting] + // VDTORS-U-NEXT: [this adjustment: -4 non-virtual] + // VDTORS-U-NEXT: 1 | void vdtors::X::zzz() + + // VDTORS-U: Thunks for 'vdtors::W::~W()' (1 entry). + // VDTORS-U-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTORS-U: VFTable indices for 'vdtors::U' (1 entries). + // VDTORS-U-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 -- + // VDTORS-U-NEXT: 0 | vdtors::U::~U() [scalar deleting] + virtual ~U(); +}; + +U u; + +struct V : virtual W { + // VDTORS-V: VFTable for 'vdtors::Z' in 'vdtors::W' in 'vdtors::V' (1 entries). + // VDTORS-V-NEXT: 0 | void vdtors::Z::z() + + // VDTORS-V: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::V' (2 entries). + // VDTORS-V-NEXT: 0 | vdtors::V::~V() [scalar deleting] + // VDTORS-V-NEXT: [this adjustment: -4 non-virtual] + // VDTORS-V-NEXT: 1 | void vdtors::X::zzz() + + // VDTORS-V: Thunks for 'vdtors::W::~W()' (1 entry). + // VDTORS-V-NEXT: 0 | this adjustment: -4 non-virtual + + // VDTORS-V: VFTable indices for 'vdtors::V' (1 entries). + // VDTORS-V-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 -- + // VDTORS-V-NEXT: 0 | vdtors::V::~V() [scalar deleting] +}; + +V v; + +struct T : virtual X { + virtual ~T(); +}; + +struct P : T, Y { + // VDTORS-P: VFTable for 'vdtors::X' in 'vdtors::T' in 'vdtors::P' (2 entries). + // VDTORS-P-NEXT: 0 | vdtors::P::~P() [scalar deleting] + // VDTORS-P-NEXT: 1 | void vdtors::X::zzz() + + // VDTORS-P-NOT: Thunks for 'vdtors::P::~P()' + virtual ~P(); +}; + +P p; + +} + namespace return_adjustment { struct X : virtual A { |