MSVC supports an extension allowing to delete an array of objects via pointer whose static type doesn't match its dynamic type. This is done via generation of special destructors - vector deleting destructors. MSVC's virtual tables always contain a pointer to the vector deleting destructor for classes with virtual destructors, so not having this extension implemented causes clang to generate code that is not compatible with the code generated by MSVC, because clang always puts a pointer to a scalar deleting destructor to the vtable. As a bonus the deletion of an array of polymorphic object will work just like it does with MSVC - no memory leaks and correct destructors are called. This patch will cause clang to emit code that is compatible with code produced by MSVC but not compatible with code produced with clang of older versions, so the new behavior can be disabled via passing -fclang-abi-compat=21 (or lower). This is yet another attempt to land vector deleting destructors support originally implemented by https://github.com/llvm/llvm-project/pull/133451. This PR contains fixes for issues reported in the original PR as well as fixes for issues related to operator delete[] search reported in several issues like https://github.com/llvm/llvm-project/pull/133950#issuecomment-2787510484 https://github.com/llvm/llvm-project/issues/134265 Fixes https://github.com/llvm/llvm-project/issues/19772
65 lines
3.3 KiB
C++
65 lines
3.3 KiB
C++
// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefix=ITANIUM --implicit-check-not=DoNotEmit
|
|
// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o - -triple x86_64-windows | FileCheck %s --check-prefix=MSABI --implicit-check-not=DoNotEmit
|
|
|
|
// FIXME: The MSVC ABI rule in use here was discussed with MS folks prior to
|
|
// them implementing virtual consteval functions, but we do not know for sure
|
|
// if this is the ABI rule they will use.
|
|
|
|
// ITANIUM-DAG: @_ZTV1A = {{.*}} constant { [2 x ptr] } {{.*}} null, {{.*}} @_ZTI1A
|
|
// MSABI-DAG: @[[A_VFTABLE:.*]] = {{.*}} constant { [1 x ptr] } {{.*}} @"??_R4A@@6B@"
|
|
struct A {
|
|
virtual consteval void DoNotEmit_f() {}
|
|
};
|
|
// ITANIUM-DAG: @a = {{.*}}global %struct.A { {{.*}} @_ZTV1A,
|
|
// MSABI-DAG: @"?a@@3UA@@A" = {{.*}}global %struct.A { ptr @"??_7A@@6B@" }
|
|
A a;
|
|
|
|
// ITANIUM-DAG: @_ZTV1B = {{.*}} constant { [4 x ptr] } {{.*}} null, ptr @_ZTI1B, ptr @_ZN1B1fEv, ptr @_ZN1B1hEv
|
|
// MSABI-DAG: @[[B_VFTABLE:.*]] = {{.*}} constant { [3 x ptr] } {{.*}} @"??_R4B@@6B@", ptr @"?f@B@@UEAAXXZ", ptr @"?h@B@@UEAAXXZ"
|
|
struct B {
|
|
virtual void f() {}
|
|
virtual consteval void DoNotEmit_g() {}
|
|
virtual void h() {}
|
|
};
|
|
// ITANIUM-DAG: @b = {{.*}}global %struct.B { {{.*}} @_ZTV1B,
|
|
// MSABI-DAG: @"?b@@3UB@@A" = {{.*}}global %struct.B { ptr @"??_7B@@6B@" }
|
|
B b;
|
|
|
|
// ITANIUM-DAG: @_ZTV1C = {{.*}} constant { [4 x ptr] } {{.*}} null, ptr @_ZTI1C, ptr @_ZN1CD1Ev, ptr @_ZN1CD0Ev
|
|
// MSABI-DAG: @[[C_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4C@@6B@", ptr @"??_EC@@UEAAPEAXI@Z"
|
|
struct C {
|
|
virtual ~C() = default;
|
|
virtual consteval C &operator=(const C&) = default;
|
|
};
|
|
// ITANIUM-DAG: @c = {{.*}}global %struct.C { {{.*}} @_ZTV1C,
|
|
// MSABI-DAG: @"?c@@3UC@@A" = {{.*}}global %struct.C { ptr @"??_7C@@6B@" }
|
|
C c;
|
|
|
|
// ITANIUM-DAG: @_ZTV1D = {{.*}} constant { [4 x ptr] } {{.*}} null, ptr @_ZTI1D, ptr @_ZN1DD1Ev, ptr @_ZN1DD0Ev
|
|
// MSABI-DAG: @[[D_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4D@@6B@", ptr @"??_ED@@UEAAPEAXI@Z"
|
|
struct D : C {};
|
|
// ITANIUM-DAG: @d = {{.*}}global { ptr } { {{.*}} @_ZTV1D,
|
|
// MSABI-DAG: @"?d@@3UD@@A" = {{.*}}global { ptr } { ptr @"??_7D@@6B@" }
|
|
D d;
|
|
|
|
// ITANIUM-DAG: @_ZTV1E = {{.*}} constant { [3 x ptr] } {{.*}} null, ptr @_ZTI1E, ptr @_ZN1E1fEv
|
|
// MSABI-DAG: @[[E_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4E@@6B@", ptr @"?f@E@@UEAAXXZ"
|
|
struct E { virtual void f() {} };
|
|
// ITANIUM-DAG: @e = {{.*}}global %struct.E { {{.*}} @_ZTV1E,
|
|
// MSABI-DAG: @"?e@@3UE@@A" = {{.*}}global %struct.E { ptr @"??_7E@@6B@" }
|
|
E e;
|
|
|
|
// ITANIUM-DAG: @_ZTV1F = {{.*}} constant { [3 x ptr] } {{.*}} null, ptr @_ZTI1F, ptr @_ZN1E1fEv
|
|
// MSABI-DAG: @[[F_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4F@@6B@", ptr @"?f@E@@UEAAXXZ"
|
|
struct F : E { virtual consteval void DoNotEmit_g(); };
|
|
// ITANIUM-DAG: @f = {{.*}}global { ptr } { {{.*}} @_ZTV1F,
|
|
// MSABI-DAG: @"?f@@3UF@@A" = {{.*}}global { ptr } { ptr @"??_7F@@6B@" }
|
|
F f;
|
|
|
|
// MSABI-DAG: @"??_7A@@6B@" = {{.*}} alias {{.*}} @[[A_VFTABLE]],
|
|
// MSABI-DAG: @"??_7B@@6B@" = {{.*}} alias {{.*}} @[[B_VFTABLE]],
|
|
// MSABI-DAG: @"??_7C@@6B@" = {{.*}} alias {{.*}} @[[C_VFTABLE]],
|
|
// MSABI-DAG: @"??_7D@@6B@" = {{.*}} alias {{.*}} @[[D_VFTABLE]],
|
|
// MSABI-DAG: @"??_7E@@6B@" = {{.*}} alias {{.*}} @[[E_VFTABLE]],
|
|
// MSABI-DAG: @"??_7F@@6B@" = {{.*}} alias {{.*}} @[[F_VFTABLE]],
|