1 // RUN: %clang_cc1 -triple arm64-apple-ios -std=c++17 -Wno-vla -fsyntax-only -verify -fptrauth-intrinsics %s
2 // RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c++17 -Wno-vla -fsyntax-only -verify -fptrauth-intrinsics %s
4 // RUN: not %clang_cc1 -triple arm64-apple-ios -std=c++17 -Wno-vla -fsyntax-only %s 2>&1 | FileCheck %s
5 // CHECK: this target does not support pointer authentication
12 constexpr unsigned dependentOperandDisc() {
13 return __builtin_ptrauth_type_discriminator(T
);
16 void test_builtin_ptrauth_type_discriminator(unsigned s
) {
17 typedef int (S::*MemFnTy
)();
19 int (S::*memFnPtr2
)();
20 constexpr unsigned d0
= __builtin_ptrauth_type_discriminator(MemFnTy
);
21 static_assert(d0
== __builtin_ptrauth_string_discriminator("_ZTSM1SFivE"));
22 static_assert(d0
== 60844);
23 static_assert(__builtin_ptrauth_type_discriminator(int (S::*)()) == d0
);
24 static_assert(__builtin_ptrauth_type_discriminator(decltype(memFnPtr
)) == d0
);
25 static_assert(__builtin_ptrauth_type_discriminator(decltype(memFnPtr2
)) == d0
);
26 static_assert(__builtin_ptrauth_type_discriminator(decltype(&S::foo
)) == d0
);
27 static_assert(dependentOperandDisc
<decltype(&S::foo
)>() == d0
);
29 constexpr unsigned d1
= __builtin_ptrauth_type_discriminator(void (S::*)(int));
30 static_assert(__builtin_ptrauth_string_discriminator("_ZTSM1SFviE") == d1
);
31 static_assert(d1
== 39121);
33 constexpr unsigned d2
= __builtin_ptrauth_type_discriminator(void (S::*)(float));
34 static_assert(__builtin_ptrauth_string_discriminator("_ZTSM1SFvfE") == d2
);
35 static_assert(d2
== 52453);
37 constexpr unsigned d3
= __builtin_ptrauth_type_discriminator(int (*())[s
]);
38 static_assert(__builtin_ptrauth_string_discriminator("FPE") == d3
);
39 static_assert(d3
== 34128);
42 constexpr unsigned d4
= __builtin_ptrauth_type_discriminator(decltype(f4
));
43 static_assert(__builtin_ptrauth_type_discriminator(int (*)(float)) == d4
);
44 static_assert(__builtin_ptrauth_string_discriminator("FifE") == d4
);
45 static_assert(d4
== 48468);
48 constexpr unsigned d5
= __builtin_ptrauth_type_discriminator(decltype(f5
));
49 static_assert(__builtin_ptrauth_type_discriminator(int (*)(int)) == d5
);
50 static_assert(__builtin_ptrauth_type_discriminator(short (*)(short)) == d5
);
51 static_assert(__builtin_ptrauth_type_discriminator(char (*)(char)) == d5
);
52 static_assert(__builtin_ptrauth_type_discriminator(long (*)(long)) == d5
);
53 static_assert(__builtin_ptrauth_type_discriminator(unsigned int (*)(unsigned int)) == d5
);
54 static_assert(__builtin_ptrauth_type_discriminator(int (&)(int)) == d5
);
55 static_assert(__builtin_ptrauth_string_discriminator("FiiE") == d5
);
56 static_assert(d5
== 2981);
60 (void)__builtin_ptrauth_type_discriminator(t
); // expected-error {{unknown type name 't'}}
61 (void)__builtin_ptrauth_type_discriminator(&t
); // expected-error {{expected a type}}
62 (void)__builtin_ptrauth_type_discriminator(decltype(vmarray
)); // expected-error {{cannot pass undiscriminated type 'decltype(vmarray)' (aka 'int[s]')}}
63 (void)__builtin_ptrauth_type_discriminator(int *); // expected-error {{cannot pass undiscriminated type 'int *' to '__builtin_ptrauth_type_discriminator'}}
64 (void)__builtin_ptrauth_type_discriminator(); // expected-error {{expected a type}}
65 (void)__builtin_ptrauth_type_discriminator(int (*)(int), int (*)(int));
66 // expected-error@-1 {{expected ')'}}
67 // expected-note@-2 {{to match this '('}}