From 1344c121f7e980364627ad9ffebd040ce90093b1 Mon Sep 17 00:00:00 2001 From: Oliver Hunt Date: Fri, 19 Sep 2025 15:37:41 -0600 Subject: [PATCH] [clang][PAC] Don't try to diagnose use of pointer auth on dependent types #159505 We can't give a correct answer for dependent types, so for now just report no ptrauth involves if the type being queried is dependent. In future we may want to distinguigh the `None` vs `Dependent` cases but that does not seem warranted for now. Fixes #159505 --- clang/lib/AST/ASTContext.cpp | 3 ++ clang/test/SemaCXX/ptrauth-type-traits.cpp | 38 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e49ff9080571e..97c59b2ceec2f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1707,6 +1707,9 @@ ASTContext::findPointerAuthContent(QualType T) const { assert(isPointerAuthenticationAvailable()); T = T.getCanonicalType(); + if (T->isDependentType()) + return PointerAuthContent::None; + if (T.hasAddressDiscriminatedPointerAuth()) return PointerAuthContent::AddressDiscriminatedData; const RecordDecl *RD = T->getAsRecordDecl(); diff --git a/clang/test/SemaCXX/ptrauth-type-traits.cpp b/clang/test/SemaCXX/ptrauth-type-traits.cpp index aefbd63fa1677..a81ef1cce25b6 100644 --- a/clang/test/SemaCXX/ptrauth-type-traits.cpp +++ b/clang/test/SemaCXX/ptrauth-type-traits.cpp @@ -8,13 +8,14 @@ // expected-no-diagnostics #ifdef __PTRAUTH__ - +#define PTRAUTH_ENABLED 1 #define NonAddressDiscriminatedVTablePtrAttr \ [[clang::ptrauth_vtable_pointer(process_independent, no_address_discrimination, no_extra_discrimination)]] #define AddressDiscriminatedVTablePtrAttr \ [[clang::ptrauth_vtable_pointer(process_independent, address_discrimination, no_extra_discrimination)]] #define ADDR_DISC_ENABLED true #else +#define PTRAUTH_ENABLED 0 #define NonAddressDiscriminatedVTablePtrAttr #define AddressDiscriminatedVTablePtrAttr #define ADDR_DISC_ENABLED false @@ -399,3 +400,38 @@ static_assert(!ASSIGNABLE_WRAPPER(RelocatableAddressDiscriminatedPrimaryBase)); static_assert(!ASSIGNABLE_WRAPPER(RelocatableAddressDiscriminatedSecondaryBase)); static_assert(!ASSIGNABLE_WRAPPER(EmbdeddedAddressDiscriminatedPolymorphicClass)); static_assert(!ASSIGNABLE_WRAPPER(RelocatableEmbdeddedAddressDiscriminatedPolymorphicClass)); + +namespace GH159505 { + class A { + virtual void f(); + }; + + template struct B { + class C : A { + A a[N]; + } d; + }; + + template struct C { + void *__ptrauth(1,1,1) ptr[N]; + static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(decltype(ptr))); + }; + template struct D { + T ptr; + static_assert(isPtrauth != __is_trivially_copyable(decltype(ptr))); + }; + + + template using Ptr = T * __ptrauth(1,1,1); + template void test() { + static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(Ptr)); + } + + auto f = test; + static_assert(!__is_trivially_copyable(B<1>)); + static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(C<1>)); + + + D d_void; + D d_void_ptrauth; +}