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