Skip to content

Commit f6c711b

Browse files
authored
[clang][PAC] Don't try to diagnose use of pointer auth on dependent types #159505 (#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 #159505
1 parent 57b673b commit f6c711b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,9 @@ ASTContext::findPointerAuthContent(QualType T) const {
17071707
assert(isPointerAuthenticationAvailable());
17081708

17091709
T = T.getCanonicalType();
1710+
if (T->isDependentType())
1711+
return PointerAuthContent::None;
1712+
17101713
if (T.hasAddressDiscriminatedPointerAuth())
17111714
return PointerAuthContent::AddressDiscriminatedData;
17121715
const RecordDecl *RD = T->getAsRecordDecl();

clang/test/SemaCXX/ptrauth-type-traits.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
// expected-no-diagnostics
99

1010
#ifdef __PTRAUTH__
11-
11+
#define PTRAUTH_ENABLED 1
1212
#define NonAddressDiscriminatedVTablePtrAttr \
1313
[[clang::ptrauth_vtable_pointer(process_independent, no_address_discrimination, no_extra_discrimination)]]
1414
#define AddressDiscriminatedVTablePtrAttr \
1515
[[clang::ptrauth_vtable_pointer(process_independent, address_discrimination, no_extra_discrimination)]]
1616
#define ADDR_DISC_ENABLED true
1717
#else
18+
#define PTRAUTH_ENABLED 0
1819
#define NonAddressDiscriminatedVTablePtrAttr
1920
#define AddressDiscriminatedVTablePtrAttr
2021
#define ADDR_DISC_ENABLED false
@@ -399,3 +400,38 @@ static_assert(!ASSIGNABLE_WRAPPER(RelocatableAddressDiscriminatedPrimaryBase));
399400
static_assert(!ASSIGNABLE_WRAPPER(RelocatableAddressDiscriminatedSecondaryBase));
400401
static_assert(!ASSIGNABLE_WRAPPER(EmbdeddedAddressDiscriminatedPolymorphicClass));
401402
static_assert(!ASSIGNABLE_WRAPPER(RelocatableEmbdeddedAddressDiscriminatedPolymorphicClass));
403+
404+
namespace GH159505 {
405+
class A {
406+
virtual void f();
407+
};
408+
409+
template <int N> struct B {
410+
class C : A {
411+
A a[N];
412+
} d;
413+
};
414+
415+
template <int N> struct C {
416+
void *__ptrauth(1,1,1) ptr[N];
417+
static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(decltype(ptr)));
418+
};
419+
template <class T, bool isPtrauth> struct D {
420+
T ptr;
421+
static_assert(isPtrauth != __is_trivially_copyable(decltype(ptr)));
422+
};
423+
424+
425+
template <class T> using Ptr = T * __ptrauth(1,1,1);
426+
template <class T> void test() {
427+
static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(Ptr<T>));
428+
}
429+
430+
auto f = test<int>;
431+
static_assert(!__is_trivially_copyable(B<1>));
432+
static_assert(PTRAUTH_ENABLED != __is_trivially_copyable(C<1>));
433+
434+
435+
D<void *, false> d_void;
436+
D<void * __ptrauth(1,1,1), PTRAUTH_ENABLED> d_void_ptrauth;
437+
}

0 commit comments

Comments
 (0)