diff options
| author | Oliver Hunt <oliver@apple.com> | 2025-08-12 13:43:07 -0700 |
|---|---|---|
| committer | Oliver Hunt <oliver@apple.com> | 2025-08-12 13:43:07 -0700 |
| commit | 5a1793a87f154649489d22b3b39432cf4da6caa8 (patch) | |
| tree | 854a429060fbdbdec8605f30d61a6940c10839ea | |
| parent | 2e9944a03e6bdda64f266aa4b9fe88d81fdf16cd (diff) | |
[clang][PAC] ptrauth_qualifier must be a feature rather than an extensionusers/ojhunt/ptrauth-qualifier-is-a-feature
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.
| -rw-r--r-- | clang/include/clang/Basic/Features.def | 2 | ||||
| -rw-r--r-- | clang/test/Preprocessor/ptrauth_extension.c | 8 | ||||
| -rw-r--r-- | clang/test/Sema/ptrauth-qualifier.c | 7 | ||||
| -rw-r--r-- | clang/test/SemaObjC/ptrauth-qualifier.m | 3 |
4 files changed, 16 insertions, 4 deletions
diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def index c58e3f2400ad..404ae9e1fca1 100644 --- a/clang/include/clang/Basic/Features.def +++ b/clang/include/clang/Basic/Features.def @@ -148,7 +148,7 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread)) FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow)) FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo)) FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics) -EXTENSION(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics) +FEATURE(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics) FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls) FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns) FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtrAddressDiscrimination) diff --git a/clang/test/Preprocessor/ptrauth_extension.c b/clang/test/Preprocessor/ptrauth_extension.c index d6b79187ba62..5a0fbaa9e0e2 100644 --- a/clang/test/Preprocessor/ptrauth_extension.c +++ b/clang/test/Preprocessor/ptrauth_extension.c @@ -1,10 +1,16 @@ // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics | \ // RUN: FileCheck %s --check-prefixes=INTRIN +// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics -pedantic-errors | \ +// RUN: FileCheck %s --check-prefixes=INTRIN + // RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls | \ // RUN: FileCheck %s --check-prefixes=NOINTRIN -#if __has_extension(ptrauth_qualifier) +// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls -pedantic-errors | \ +// RUN: FileCheck %s --check-prefixes=NOINTRIN + +#if __has_feature(ptrauth_qualifier) // INTRIN: has_ptrauth_qualifier void has_ptrauth_qualifier() {} #else diff --git a/clang/test/Sema/ptrauth-qualifier.c b/clang/test/Sema/ptrauth-qualifier.c index 5d932b724f07..18fada51bcbb 100644 --- a/clang/test/Sema/ptrauth-qualifier.c +++ b/clang/test/Sema/ptrauth-qualifier.c @@ -1,7 +1,8 @@ // RUN: %clang_cc1 -triple arm64-apple-ios -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s // RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s +// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics -pedantic-errors -DPEDANTIC_ERRORS %s -#if !__has_extension(ptrauth_qualifier) +#if !__has_feature(ptrauth_qualifier) // This error means that the __ptrauth qualifier availability test says that it // is not available. This error is not expected in the output, if it is seen // there is a feature detection regression. @@ -66,6 +67,7 @@ intp redeclaration3 = 0; // expected-error{{redefinition o 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)')}} 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)')}} +#ifndef PEDANTIC_ERRORS static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_DATA_KEY) : 1, int * : 0, default : 0)); static_assert(_Generic(typeof(valid0), int * __ptrauth(VALID_CODE_KEY) : 0, default : 1)); static_assert(_Generic(typeof_unqual(valid0), int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, default : 0)); @@ -73,6 +75,7 @@ static_assert(_Generic(valid0, int * __ptrauth(VALID_DATA_KEY) : 0, int * : 1, d static_assert(_Generic(array0, int * __ptrauth(VALID_DATA_KEY) * : 1, default : 0)); static_assert(_Generic(*array1, int * : 1, default : 0)); +#endif void test_code(intp p) { 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) { __attribute__((overloadable)) int overload_func(int **); __attribute__((overloadable)) float overload_func(int * __ptrauth(VALID_DATA_KEY) *); +#ifndef PEDANTIC_ERRORS static_assert(_Generic(typeof(overload_func(&ptr0)), int : 1, default : 0)); static_assert(_Generic(typeof(overload_func(&valid0)), float : 1, default : 0)); +#endif 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}} diff --git a/clang/test/SemaObjC/ptrauth-qualifier.m b/clang/test/SemaObjC/ptrauth-qualifier.m index 74bbe6f09899..bd64dc85d21a 100644 --- a/clang/test/SemaObjC/ptrauth-qualifier.m +++ b/clang/test/SemaObjC/ptrauth-qualifier.m @@ -1,7 +1,8 @@ // RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s // RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s +// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics -pedantic-errors %s -#if !__has_extension(ptrauth_qualifier) +#if !__has_feature(ptrauth_qualifier) // This error means that the __ptrauth qualifier availability test says that it // is not available. This error is not expected in the output, if it is seen // there is a feature detection regression. |
