diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 32c8f6209a693..687cd46773f43 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1648,6 +1648,9 @@ ASTContext::findPointerAuthContent(QualType T) const { if (!RD) return PointerAuthContent::None; + if (RD->isInvalidDecl()) + return PointerAuthContent::None; + if (auto Existing = RecordContainsAddressDiscriminatedPointerAuth.find(RD); Existing != RecordContainsAddressDiscriminatedPointerAuth.end()) return Existing->second; @@ -3517,7 +3520,6 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx, uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) { assert(!T->isDependentType() && "cannot compute type discriminator of a dependent type"); - SmallString<256> Str; llvm::raw_svector_ostream Out(Str); diff --git a/clang/test/SemaCXX/ptrauth-nested-incomplete-types.cpp b/clang/test/SemaCXX/ptrauth-nested-incomplete-types.cpp new file mode 100644 index 0000000000000..8fad2fb05bc6d --- /dev/null +++ b/clang/test/SemaCXX/ptrauth-nested-incomplete-types.cpp @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -fptrauth-intrinsics -fsyntax-only -ferror-limit 1 -verify -std=c++26 %s +// RUN: %clang_cc1 -fptrauth-intrinsics -fsyntax-only -ferror-limit 1 -verify -std=c++03 %s +// RUN: %clang_cc1 -fsyntax-only -ferror-limit 1 -verify -std=c++03 %s + +/// Force two errors so we hit the error limit leading to skip of template instantiation +# "" // expected-error {{invalid preprocessing directive}} +# "" +// expected-error@* {{too many errors emitted}} + +template +struct a {}; +struct test_polymorphic { + virtual ~test_polymorphic(); + a field; +}; +static_assert(__is_trivially_relocatable(test_polymorphic)); + +struct test_struct { + test_struct(int) {} + void test_instantiate() { + test_struct d(0); + } + void test_type_trait_query() { + __is_trivially_relocatable(test_struct); + } + a e; +}; + +struct test_struct2 { + test_struct member; + void test() { + test_struct2 t{.member = {0}}; + } +}; + +struct test_subclass : test_struct { + test_subclass() : test_struct(0) { + } + + void test_subclass_instantiation() { + test_subclass subclass{}; + } + void test_subclass_type_trait_query() { + __is_trivially_relocatable(test_subclass); + } +};