xref: /llvm-project/clang/test/CodeGenCXX/ptrauth-apple-kext-indirect-call.cpp (revision 1b8ab2f08998d3220e5d95003d47bb3d7cac966b)
1 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fapple-kext -emit-llvm -o - %s | FileCheck %s
2 
3 // CHECK: @_ZTV5TemplIiE = internal unnamed_addr constant { [5 x ptr] } { [5 x ptr] [ptr null, ptr @_ZTI5TemplIiE, ptr ptrauth (ptr @_ZN5TemplIiE1fEv, i32 0, i64 22189, ptr getelementptr inbounds ({ [5 x ptr] }, ptr @_ZTV5TemplIiE, i32 0, i32 0, i32 2)), ptr ptrauth (ptr @_ZN5TemplIiE1gEv, i32 0, i64 9912, ptr getelementptr inbounds ({ [5 x ptr] }, ptr @_ZTV5TemplIiE, i32 0, i32 0, i32 3)), ptr null] }, align 8
4 
5 struct Base {
6   virtual void abc(void) const;
7 };
8 
abc(void) const9 void Base::abc(void) const {}
10 
FUNC(Base * p)11 void FUNC(Base* p) {
12   p->Base::abc();
13 }
14 
15 // CHECK: getelementptr inbounds (ptr, ptr @_ZTV4Base, i64 2)
16 // CHECK-NOT: call void @_ZNK4Base3abcEv
17 
18 template<class T>
19 struct Templ {
fTempl20   virtual void f() {}
gTempl21   virtual void g() {}
22 };
23 template<class T>
24 struct SubTempl : public Templ<T> {
fSubTempl25   virtual void f() {} // override
gSubTempl26   virtual void g() {} // override
27 };
28 
f(SubTempl<int> * t)29 void f(SubTempl<int>* t) {
30   // Qualified calls go through the (qualified) vtable in apple-kext mode.
31   // Since t's this pointer points to SubTempl's vtable, the call needs
32   // to load Templ<int>'s vtable.  Hence, Templ<int>::g needs to be
33   // instantiated in this TU, for it's referenced by the vtable.
34   // (This happens only in apple-kext mode; elsewhere virtual calls can always
35   // use the vtable pointer off this instead of having to load the vtable
36   // symbol.)
37   t->Templ::f();
38 }
39 
40 // CHECK: getelementptr inbounds (ptr, ptr @_ZTV5TemplIiE, i64 2)
41 // CHECK: define internal void @_ZN5TemplIiE1fEv(ptr noundef nonnull align {{[0-9]+}} dereferenceable(8) %this)
42 // CHECK: define internal void @_ZN5TemplIiE1gEv(ptr noundef nonnull align {{[0-9]+}} dereferenceable(8) %this)
43