llvm-project/clang/test/Preprocessor/ptrauth_extension.c
Oliver Hunt 624b724ca6
[clang][PAC] ptrauth_qualifier and ptrauth_intrinsic should only be available on Darwin (#153912)
For backwards compatibility reasons the `ptrauth_qualifier` and
`ptrauth_intrinsic` features need to be testable with `__has_feature()`
on Apple platforms, but for other platforms this backwards compatibility
issue does not exist.

This PR resolves these issues by making the `ptrauth_qualifier` and
`ptrauth_intrinsic` tests conditional upon a darwin target. This also
allows us to revert the ptrauth_qualifier check from an extension to a
feature test again, as is required on these platforms.

At the same time we introduce a new predefined macro `__PTRAUTH__` that
answers the same question as `__has_feature(ptrauth_qualifier)` and
`__has_feature(ptrauth_intrinsic)` as those tests are synonymous and
only exist separately for compatibility reasons.

The requirement to test for the `__PTRAUTH__` macro also resolves the
hazard presented by mixing the `ptrauth_qualifier` flag (that impacts
ABI and security policies) with `-pedantics-errors`, which makes
`__has_extension` return false for all extensions.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-08-18 20:29:26 +00:00

36 lines
1.2 KiB
C

// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-intrinsics | \
// RUN: FileCheck %s --check-prefixes=INTRIN
// RUN: %clang_cc1 -E %s -triple=aarch64 -fptrauth-calls | \
// RUN: FileCheck %s --check-prefixes=NOINTRIN
// RUN: %clang_cc1 -E %s -DIS_DARWIN -triple=arm64e-apple-darwin -fptrauth-intrinsics | \
// RUN: FileCheck %s --check-prefixes=INTRIN,INTRIN_MAC
// RUN: %clang_cc1 -E %s -DIS_DARWIN -triple=arm64e-apple-darwin -fptrauth-calls | \
// RUN: FileCheck %s --check-prefixes=NOINTRIN
#if defined(IS_DARWIN) && __has_extension(ptrauth_qualifier)
// INTRIN_MAC: has_ptrauth_qualifier1
void has_ptrauth_qualifier1() {}
#ifndef __PTRAUTH__
#error ptrauth_qualifier extension present without predefined test macro
#endif
#endif
#if defined(IS_DARWIN) && __has_feature(ptrauth_qualifier)
// INTRIN_MAC: has_ptrauth_qualifier2
void has_ptrauth_qualifier2() {}
#ifndef __PTRAUTH__
#error ptrauth_qualifier extension present without predefined test macro
#endif
#endif
#if defined(__PTRAUTH__)
// INTRIN: has_ptrauth_qualifier3
void has_ptrauth_qualifier3() {}
#endif
#if !defined(__PTRAUTH__) && !__has_feature(ptrauth_qualifier) && !__has_extension(ptrauth_qualifier)
// NOINTRIN: no_ptrauth_qualifier
void no_ptrauth_qualifier() {}
#endif