Skip to content

Commit 5a1793a

Browse files
committed
[clang][PAC] ptrauth_qualifier must be a feature rather than an extension
Under `-pedantic-errors` extensions (as detected by __has_extension) are not enabled (or rather the tests return false). As the ptrauth qualifier impacts the ABI this is not sound, so this PR returns the ptrauth qualifier to being detected through a feature check.
1 parent 2e9944a commit 5a1793a

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
148148
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
149149
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
150150
FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
151-
EXTENSION(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
151+
FEATURE(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
152152
FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
153153
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
154154
FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtrAddressDiscrimination)

clang/test/Preprocessor/ptrauth_extension.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics | \
22
// RUN: FileCheck %s --check-prefixes=INTRIN
33

4+
// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics -pedantic-errors | \
5+
// RUN: FileCheck %s --check-prefixes=INTRIN
6+
47
// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls | \
58
// RUN: FileCheck %s --check-prefixes=NOINTRIN
69

7-
#if __has_extension(ptrauth_qualifier)
10+
// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls -pedantic-errors | \
11+
// RUN: FileCheck %s --check-prefixes=NOINTRIN
12+
13+
#if __has_feature(ptrauth_qualifier)
814
// INTRIN: has_ptrauth_qualifier
915
void has_ptrauth_qualifier() {}
1016
#else

clang/test/Sema/ptrauth-qualifier.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %clang_cc1 -triple arm64-apple-ios -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
22
// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
3+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics -pedantic-errors -DPEDANTIC_ERRORS %s
34

4-
#if !__has_extension(ptrauth_qualifier)
5+
#if !__has_feature(ptrauth_qualifier)
56
// This error means that the __ptrauth qualifier availability test says that it
67
// is not available. This error is not expected in the output, if it is seen
78
// there is a feature detection regression.
@@ -66,13 +67,15 @@ intp redeclaration3 = 0; // expected-error{{redefinition o
6667
void illegal0(intp __ptrauth(VALID_DATA_KEY)); // expected-error {{parameter type may not be qualified with '__ptrauth'; type is '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
6768
intp __ptrauth(VALID_DATA_KEY) illegal1(void); // expected-error {{return type may not be qualified with '__ptrauth'; type is '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
6869

70+
#ifndef PEDANTIC_ERRORS
6971
static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_DATA_KEY) : 1, int * : 0, default : 0));
7072
static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_CODE_KEY) : 0, default : 1));
7173
static_assert(_Generic(typeof_unqual(valid0), int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, default : 0));
7274
static_assert(_Generic(valid0, int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, default : 0)); // expected-warning {{association of type 'int *__ptrauth(2,0,0)' will never be selected}}
7375

7476
static_assert(_Generic(array0, int * __ptrauth(VALID_DATA_KEY) * : 1, default : 0));
7577
static_assert(_Generic(*array1, int * : 1, default : 0));
78+
#endif
7679

7780
void test_code(intp p) {
7881
p = (intp __ptrauth(VALID_DATA_KEY)) 0; // expected-error {{cannot cast to '__ptrauth'-qualified type '__ptrauth(2,0,0) intp' (aka 'int *__ptrauth(2,0,0)')}}
@@ -99,8 +102,10 @@ void test_array(void) {
99102
__attribute__((overloadable)) int overload_func(int **);
100103
__attribute__((overloadable)) float overload_func(int * __ptrauth(VALID_DATA_KEY) *);
101104

105+
#ifndef PEDANTIC_ERRORS
102106
static_assert(_Generic(typeof(overload_func(&ptr0)), int : 1, default : 0));
103107
static_assert(_Generic(typeof(overload_func(&valid0)), float : 1, default : 0));
108+
#endif
104109

105110
void func(int array[__ptrauth(VALID_DATA_KEY) 10]); // expected-error {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'int[10]' is invalid}}
106111

clang/test/SemaObjC/ptrauth-qualifier.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s
22
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s
3+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics -pedantic-errors %s
34

4-
#if !__has_extension(ptrauth_qualifier)
5+
#if !__has_feature(ptrauth_qualifier)
56
// This error means that the __ptrauth qualifier availability test says that it
67
// is not available. This error is not expected in the output, if it is seen
78
// there is a feature detection regression.

0 commit comments

Comments
 (0)