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