xref: /aosp_15_r20/external/clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fapple-kext -fno-rtti -emit-llvm -o - %s | FileCheck %s
2*67e74705SXin Li 
3*67e74705SXin Li // CHECK: @_ZTV5TemplIiE = internal unnamed_addr constant [7 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.Templ*)* @_ZN5TemplIiED1Ev to i8*), i8* bitcast (void (%struct.Templ*)* @_ZN5TemplIiED0Ev to i8*), i8* bitcast (void (%struct.Templ*)* @_ZN5TemplIiE1fEv to i8*), i8* bitcast (void (%struct.Templ*)* @_ZN5TemplIiE1gEv to i8*), i8* null]
4*67e74705SXin Li 
5*67e74705SXin Li struct B1 {
6*67e74705SXin Li   virtual ~B1();
7*67e74705SXin Li };
8*67e74705SXin Li 
~B1()9*67e74705SXin Li B1::~B1() {}
10*67e74705SXin Li 
DELETE(B1 * pb1)11*67e74705SXin Li void DELETE(B1 *pb1) {
12*67e74705SXin Li   pb1->B1::~B1();
13*67e74705SXin Li }
14*67e74705SXin Li // CHECK-LABEL: define void @_ZN2B1D0Ev
15*67e74705SXin Li // CHECK: [[T1:%.*]] = load void (%struct.B1*)*, void (%struct.B1*)** getelementptr inbounds (void (%struct.B1*)*, void (%struct.B1*)** bitcast ([5 x i8*]* @_ZTV2B1 to void (%struct.B1*)**), i64 2)
16*67e74705SXin Li // CHECK-NEXT: call void [[T1]](%struct.B1* [[T2:%.*]])
17*67e74705SXin Li // CHECK-LABEL: define void @_Z6DELETEP2B1
18*67e74705SXin Li // CHECK: [[T3:%.*]] = load void (%struct.B1*)*, void (%struct.B1*)** getelementptr inbounds (void (%struct.B1*)*, void (%struct.B1*)** bitcast ([5 x i8*]* @_ZTV2B1 to void (%struct.B1*)**), i64 2)
19*67e74705SXin Li // CHECK-NEXT:  call void [[T3]](%struct.B1* [[T4:%.*]])
20*67e74705SXin Li 
21*67e74705SXin Li template<class T>
22*67e74705SXin Li struct Templ {
23*67e74705SXin Li   virtual ~Templ(); // Out-of-line so that the destructor doesn't cause a vtable
fTempl24*67e74705SXin Li   virtual void f() {}
gTempl25*67e74705SXin Li   virtual void g() {}
26*67e74705SXin Li };
27*67e74705SXin Li template<class T>
28*67e74705SXin Li struct SubTempl : public Templ<T> {
~SubTemplSubTempl29*67e74705SXin Li   virtual ~SubTempl() {} // override
fSubTempl30*67e74705SXin Li   virtual void f() {} // override
gSubTempl31*67e74705SXin Li   virtual void g() {} // override
32*67e74705SXin Li };
33*67e74705SXin Li 
f(SubTempl<int> * t)34*67e74705SXin Li void f(SubTempl<int>* t) {
35*67e74705SXin Li   // Qualified calls go through the (qualified) vtable in apple-kext mode.
36*67e74705SXin Li   // Since t's this pointer points to SubTempl's vtable, the call needs
37*67e74705SXin Li   // to load Templ<int>'s vtable.  Hence, Templ<int>::g needs to be
38*67e74705SXin Li   // instantiated in this TU, for it's referenced by the vtable.
39*67e74705SXin Li   // (This happens only in apple-kext mode; elsewhere virtual calls can always
40*67e74705SXin Li   // use the vtable pointer off this instead of having to load the vtable
41*67e74705SXin Li   // symbol.)
42*67e74705SXin Li   t->Templ::~Templ();
43*67e74705SXin Li }
44*67e74705SXin Li 
45*67e74705SXin Li // CHECK: getelementptr inbounds (void (%struct.Templ*)*, void (%struct.Templ*)** bitcast ([7 x i8*]* @_ZTV5TemplIiE to void (%struct.Templ*)**), i64 2)
46*67e74705SXin Li // CHECK: declare void @_ZN5TemplIiED0Ev(%struct.Templ*)
47*67e74705SXin Li // CHECK: define internal void @_ZN5TemplIiE1fEv(%struct.Templ* %this)
48*67e74705SXin Li // CHECK: define internal void @_ZN5TemplIiE1gEv(%struct.Templ* %this)
49