Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ void ASTContext::setRelocationInfoForCXXRecord(
RelocatableClasses.insert({D, Info});
}

static bool primaryBaseHaseAddressDiscriminatedVTableAuthentication(
static bool primaryBaseHasAddressDiscriminatedVTableAuthentication(
const ASTContext &Context, const CXXRecordDecl *Class) {
if (!Class->isPolymorphic())
return false;
Expand Down Expand Up @@ -1672,7 +1672,14 @@ ASTContext::findPointerAuthContent(QualType T) const {
return Result != PointerAuthContent::AddressDiscriminatedData;
};
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
if (primaryBaseHaseAddressDiscriminatedVTableAuthentication(*this, CXXRD) &&
// `primaryBaseHasAddressDiscriminatedVTableAuthentication` requires a
// non-null CXX record decl definition which might not be available if we
// are dealing with a non-instantiated template. It might be the case if the
// template was not instantiated due to a prior fatal error. See the
// corresponding check in the `Sema::InstantiatingTemplate` constructor.
if (getDiagnostics().hasFatalErrorOccurred())
return PointerAuthContent::None;
if (primaryBaseHasAddressDiscriminatedVTableAuthentication(*this, CXXRD) &&
!ShouldContinueAfterUpdate(
PointerAuthContent::AddressDiscriminatedVTable))
return SaveResultAndReturn();
Expand Down
28 changes: 28 additions & 0 deletions clang/test/SemaCXX/ptrauth-template-instantiation-aborted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clang_cc1 -fptrauth-intrinsics -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 <typename>
struct a {};

struct b {
b(int) {}
void c() {
/// Trigger the following call stack:
/// ...
/// clang::ASTContext::findPointerAuthContent(clang::QualType) const /path/to/llvm-project/clang/lib/AST/ASTContext.cpp
/// clang::ASTContext::containsAddressDiscriminatedPointerAuth(clang::QualType) const /path/to/llvm-project/clang/lib/AST/ASTContext.cpp
/// clang::QualType::isCXX{11|98}PODType(clang::ASTContext const&) const /path/to/llvm-project/clang/lib/AST/Type.cpp
/// clang::QualType::isPODType(clang::ASTContext const&) const /path/to/llvm-project/clang/lib/AST/Type.cpp
/// SelfReferenceChecker /path/to/llvm-project/clang/lib/Sema/SemaDecl.cpp
/// CheckSelfReference /path/to/llvm-project/clang/lib/Sema/SemaDecl.cpp
/// clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) /path/to/llvm-project/clang/lib/Sema/SemaDecl.cpp
/// ...
b d(0);
}
a<int> e;
};