xref: /llvm-project/clang/test/Preprocessor/ptrauth_feature.c (revision 3b162f73d8027dcd8261666a40e9bdfb40f4dacc)
1 //// Note: preprocessor features exactly match corresponding clang driver flags. However, some flags are only intended to be used in combination with other ones.
2 //// For example, -fptrauth-init-fini will not affect codegen without -fptrauth-calls, but the preprocessor feature would be set anyway.
3 
4 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics | \
5 // RUN:   FileCheck %s --check-prefixes=INTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
6 
7 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls | \
8 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,CALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
9 
10 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-returns | \
11 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,RETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
12 
13 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-vtable-pointer-address-discrimination | \
14 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,VPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
15 
16 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-vtable-pointer-type-discrimination | \
17 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,VPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
18 
19 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-type-info-vtable-pointer-discrimination | \
20 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,TYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
21 
22 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-function-pointer-type-discrimination | \
23 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,FUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
24 
25 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-init-fini | \
26 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,INITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
27 
28 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-init-fini-address-discrimination | \
29 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,INITFINI_ADDR_DISCR,NOGOTOS,NOELFGOT
30 
31 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-indirect-gotos | \
32 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,GOTOS,NOELFGOT
33 
34 // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-elf-got | \
35 // RUN:   FileCheck %s --check-prefixes=NOINTRIN,NOCALLS,NORETS,NOVPTR_ADDR_DISCR,NOVPTR_TYPE_DISCR,NOTYPE_INFO_DISCR,NOFUNC,NOINITFINI,NOINITFINI_ADDR_DISCR,NOGOTOS,ELFGOT
36 
37 #if __has_feature(ptrauth_intrinsics)
38 // INTRIN: has_ptrauth_intrinsics
39 void has_ptrauth_intrinsics() {}
40 #else
41 // NOINTRIN: no_ptrauth_intrinsics
42 void no_ptrauth_intrinsics() {}
43 #endif
44 
45 #if __has_feature(ptrauth_calls)
46 // CALLS: has_ptrauth_calls
47 void has_ptrauth_calls() {}
48 #else
49 // NOCALLS: no_ptrauth_calls
50 void no_ptrauth_calls() {}
51 #endif
52 
53 // This is always enabled when ptrauth_calls is enabled
54 #if __has_feature(ptrauth_member_function_pointer_type_discrimination)
55 // CALLS: has_ptrauth_member_function_pointer_type_discrimination
56 void has_ptrauth_member_function_pointer_type_discrimination() {}
57 #else
58 // NOCALLS: no_ptrauth_member_function_pointer_type_discrimination
59 void no_ptrauth_member_function_pointer_type_discrimination() {}
60 #endif
61 
62 #if __has_feature(ptrauth_returns)
63 // RETS: has_ptrauth_returns
64 void has_ptrauth_returns() {}
65 #else
66 // NORETS: no_ptrauth_returns
67 void no_ptrauth_returns() {}
68 #endif
69 
70 #if __has_feature(ptrauth_vtable_pointer_address_discrimination)
71 // VPTR_ADDR_DISCR: has_ptrauth_vtable_pointer_address_discrimination
72 void has_ptrauth_vtable_pointer_address_discrimination() {}
73 #else
74 // NOVPTR_ADDR_DISCR: no_ptrauth_vtable_pointer_address_discrimination
75 void no_ptrauth_vtable_pointer_address_discrimination() {}
76 #endif
77 
78 #if __has_feature(ptrauth_vtable_pointer_type_discrimination)
79 // VPTR_TYPE_DISCR: has_ptrauth_vtable_pointer_type_discrimination
80 void has_ptrauth_vtable_pointer_type_discrimination() {}
81 #else
82 // NOVPTR_TYPE_DISCR: no_ptrauth_vtable_pointer_type_discrimination
83 void no_ptrauth_vtable_pointer_type_discrimination() {}
84 #endif
85 
86 #if __has_feature(ptrauth_type_info_vtable_pointer_discrimination)
87 // TYPE_INFO_DISCR: has_ptrauth_type_info_vtable_pointer_discrimination
88 void has_ptrauth_type_info_vtable_pointer_discrimination() {}
89 #else
90 // NOTYPE_INFO_DISCR: no_ptrauth_type_info_vtable_pointer_discrimination
91 void no_ptrauth_type_info_vtable_pointer_discrimination() {}
92 #endif
93 
94 #if __has_feature(ptrauth_function_pointer_type_discrimination)
95 // FUNC: has_ptrauth_function_pointer_type_discrimination
96 void has_ptrauth_function_pointer_type_discrimination() {}
97 #else
98 // NOFUNC: no_ptrauth_function_pointer_type_discrimination
99 void no_ptrauth_function_pointer_type_discrimination() {}
100 #endif
101 
102 #if __has_feature(ptrauth_init_fini)
103 // INITFINI: has_ptrauth_init_fini
104 void has_ptrauth_init_fini() {}
105 #else
106 // NOINITFINI: no_ptrauth_init_fini
107 void no_ptrauth_init_fini() {}
108 #endif
109 
110 #if __has_feature(ptrauth_init_fini_address_discrimination)
111 // INITFINI_ADDR_DISCR: has_ptrauth_init_fini_address_discrimination
112 void has_ptrauth_init_fini_address_discrimination() {}
113 #else
114 // NOINITFINI_ADDR_DISCR: no_ptrauth_init_fini_address_discrimination
115 void no_ptrauth_init_fini_address_discrimination() {}
116 #endif
117 
118 #if __has_feature(ptrauth_indirect_gotos)
119 // GOTOS: has_ptrauth_indirect_gotos
120 void has_ptrauth_indirect_gotos() {}
121 #else
122 // NOGOTOS: no_ptrauth_indirect_gotos
123 void no_ptrauth_indirect_gotos() {}
124 #endif
125 
126 #if __has_feature(ptrauth_elf_got)
127 // ELFGOT: has_ptrauth_elf_got
128 void has_ptrauth_elf_got() {}
129 #else
130 // NOELFGOT: no_ptrauth_elf_got
131 void no_ptrauth_elf_got() {}
132 #endif
133