1*67e74705SXin Li // RUN: %clang_cc1 -triple arm64-none-linux-gnu -emit-llvm -w -o - %s | FileCheck %s
2*67e74705SXin Li
3*67e74705SXin Li // Check differences between the generic Itanium ABI, the AArch32 version and
4*67e74705SXin Li // the AArch64 version.
5*67e74705SXin Li
6*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
7*67e74705SXin Li
8*67e74705SXin Li // The ABI says that the key function is the "textually first, non-inline,
9*67e74705SXin Li // non-pure, virtual member function". The generic version decides this after
10*67e74705SXin Li // the completion of the class definition; the AArch32 version decides this at
11*67e74705SXin Li // the end of the translation unit.
12*67e74705SXin Li
13*67e74705SXin Li // We construct a class which needs a VTable here under generic ABI, but not
14*67e74705SXin Li // AArch32.
15*67e74705SXin Li
16*67e74705SXin Li // (see next section for explanation of guard)
17*67e74705SXin Li // CHECK: @_ZGVZ15guard_variablesiE4mine = internal global i64 0
18*67e74705SXin Li
19*67e74705SXin Li // CHECK: @_ZTV16CheckKeyFunction =
20*67e74705SXin Li struct CheckKeyFunction {
21*67e74705SXin Li virtual void foo();
22*67e74705SXin Li };
23*67e74705SXin Li
24*67e74705SXin Li // This is not inline when CheckKeyFunction is completed, so
25*67e74705SXin Li // CheckKeyFunction::foo is the key function. VTables should be emitted.
foo()26*67e74705SXin Li inline void CheckKeyFunction::foo() {
27*67e74705SXin Li }
28*67e74705SXin Li
29*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
30*67e74705SXin Li
31*67e74705SXin Li // Guard variables only specify and use the low bit to determine status, rather
32*67e74705SXin Li // than the low byte as in the generic Itanium ABI. However, unlike 32-bit ARM,
33*67e74705SXin Li // they *are* 64-bits wide so check that in case confusion has occurred.
34*67e74705SXin Li
35*67e74705SXin Li class Guarded {
36*67e74705SXin Li public:
37*67e74705SXin Li Guarded(int i);
38*67e74705SXin Li ~Guarded();
39*67e74705SXin Li };
40*67e74705SXin Li
guard_variables(int a)41*67e74705SXin Li void guard_variables(int a) {
42*67e74705SXin Li static Guarded mine(a);
43*67e74705SXin Li // CHECK: [[GUARDBIT:%[0-9]+]] = and i8 {{%[0-9]+}}, 1
44*67e74705SXin Li // CHECK: icmp eq i8 [[GUARDBIT]], 0
45*67e74705SXin Li
46*67e74705SXin Li // As guards are 64-bit, these helpers should take 64-bit pointers.
47*67e74705SXin Li // CHECK: call i32 @__cxa_guard_acquire(i64*
48*67e74705SXin Li // CHECK: call void @__cxa_guard_release(i64*
49*67e74705SXin Li }
50*67e74705SXin Li
51*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
52*67e74705SXin Li
53*67e74705SXin Li // Member function pointers use the adj field to distinguish between virtual and
54*67e74705SXin Li // nonvirtual members. As a result the adjustment is shifted (if ptr was used, a
55*67e74705SXin Li // mask would be expected instead).
56*67e74705SXin Li
57*67e74705SXin Li class C {
58*67e74705SXin Li int a();
59*67e74705SXin Li virtual int b();
60*67e74705SXin Li };
61*67e74705SXin Li
62*67e74705SXin Li
member_pointer(C & c,int (C::* func)())63*67e74705SXin Li int member_pointer(C &c, int (C::*func)()) {
64*67e74705SXin Li // CHECK: ashr i64 %[[MEMPTRADJ:[0-9a-z.]+]], 1
65*67e74705SXin Li // CHECK: %[[ISVIRTUAL:[0-9]+]] = and i64 %[[MEMPTRADJ]], 1
66*67e74705SXin Li // CHECK: icmp ne i64 %[[ISVIRTUAL]], 0
67*67e74705SXin Li return (c.*func)();
68*67e74705SXin Li }
69*67e74705SXin Li
70*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
71*67e74705SXin Li
72*67e74705SXin Li // AArch64 PCS says that va_list type is based on "struct __va_list ..." in the
73*67e74705SXin Li // std namespace, which means it should mangle as "St9__va_list".
74*67e74705SXin Li
75*67e74705SXin Li // CHECK: @_Z7va_funcSt9__va_list
va_func(__builtin_va_list l)76*67e74705SXin Li void va_func(__builtin_va_list l) {
77*67e74705SXin Li }
78*67e74705SXin Li
79*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
80*67e74705SXin Li
81*67e74705SXin Li // AArch64 constructors (like generic Itanium, but unlike AArch32) do not return
82*67e74705SXin Li // "this".
83*67e74705SXin Li
test_constructor()84*67e74705SXin Li void test_constructor() {
85*67e74705SXin Li Guarded g(42);
86*67e74705SXin Li // CHECK: call void @_ZN7GuardedC1Ei
87*67e74705SXin Li }
88*67e74705SXin Li
89*67e74705SXin Li ////////////////////////////////////////////////////////////////////////////////
90*67e74705SXin Li
91*67e74705SXin Li // In principle the AArch32 ABI allows this to be accomplished via a call to
92*67e74705SXin Li // __aeabi_atexit instead of __cxa_atexit. Clang doesn't make use of this at the
93*67e74705SXin Li // moment, but it's definitely not allowed for AArch64.
94*67e74705SXin Li
95*67e74705SXin Li // CHECK: call i32 @__cxa_atexit
96*67e74705SXin Li Guarded g(42);
97