Skip to content

Conversation

ojhunt
Copy link
Contributor

@ojhunt ojhunt commented Sep 19, 2025

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

@ojhunt ojhunt self-assigned this Sep 19, 2025
@ojhunt ojhunt requested a review from ahatanak September 19, 2025 22:08
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2025

@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/159859.diff

2 Files Affected:

  • (modified) clang/lib/AST/ASTContext.cpp (+3)
  • (modified) clang/test/SemaCXX/ptrauth-type-traits.cpp (+37-1)
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 <int N> struct B {
+    class C : A {
+      A a[N];
+    } d;
+  };
+
+  template <int N> struct C {
+    void *__ptrauth(1,1,1) ptr[N];
+    static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(decltype(ptr)));
+  };
+  template <class T, bool isPtrauth> struct D {
+    T ptr;
+    static_assert(isPtrauth != __is_trivially_copyable(decltype(ptr)));
+  };
+
+
+  template <class T> using Ptr = T * __ptrauth(1,1,1);
+  template <class T> void test() {
+    static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(Ptr<T>));
+  }
+
+  auto f = test<int>;
+  static_assert(!__is_trivially_copyable(B<1>));
+  static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(C<1>));
+
+
+  D<void *, false> d_void;
+  D<void * __ptrauth(1,1,1), PTRAUTH_ENABLED> d_void_ptrauth;
+}

…ypes #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
@ojhunt ojhunt force-pushed the users/ojhunt/GH159505 branch from cf382c0 to 1344c12 Compare September 19, 2025 22:09
@ojhunt ojhunt merged commit f6c711b into main Sep 20, 2025
9 checks passed
@ojhunt ojhunt deleted the users/ojhunt/GH159505 branch September 20, 2025 01:34
@porglezomp
Copy link
Contributor

This also needs to be cherry-picked to release/21.x

SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
…ypes llvm#159505 (llvm#159859)

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 llvm#159505
YixingZhang007 pushed a commit to YixingZhang007/llvm-project that referenced this pull request Sep 27, 2025
…ypes llvm#159505 (llvm#159859)

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 llvm#159505
@ojhunt ojhunt added this to the LLVM 21.x Release milestone Sep 29, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Sep 29, 2025
@ojhunt
Copy link
Contributor Author

ojhunt commented Sep 29, 2025

/cherry-pick f6c711b

@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2025

/pull-request #161288

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

Clang parser crash with -fptrauth-intrinsics enabled - Assertion failed: (!T->isDependentType() && "should not see dependent types here")
4 participants