Skip to content

Commit 3fe88ff

Browse files
ojhuntdvbuka
authored andcommitted
[PAC][clang] Correct handling of ptrauth queries of incomplete types (llvm#164528)
In normal circumstances we can never get to this point as earlier Sema checks will have already have prevented us from making these queries. However in some cases, for example a sufficiently large number of errors, clang can start allowing incomplete types in records. This means a number of the internal interfaces can end up perform type trait queries that require querying the pointer authentication properties of types that contain incomplete types. While the trait queries attempt to guard against incomplete types, those tests fail in this case as the incomplete types are actually nested in the seemingly complete parent type.
1 parent 2bec3bb commit 3fe88ff

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,9 @@ ASTContext::findPointerAuthContent(QualType T) const {
16481648
if (!RD)
16491649
return PointerAuthContent::None;
16501650

1651+
if (RD->isInvalidDecl())
1652+
return PointerAuthContent::None;
1653+
16511654
if (auto Existing = RecordContainsAddressDiscriminatedPointerAuth.find(RD);
16521655
Existing != RecordContainsAddressDiscriminatedPointerAuth.end())
16531656
return Existing->second;
@@ -3517,7 +3520,6 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
35173520
uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) {
35183521
assert(!T->isDependentType() &&
35193522
"cannot compute type discriminator of a dependent type");
3520-
35213523
SmallString<256> Str;
35223524
llvm::raw_svector_ostream Out(Str);
35233525

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %clang_cc1 -fptrauth-intrinsics -fsyntax-only -ferror-limit 1 -verify -std=c++26 %s
2+
// RUN: %clang_cc1 -fptrauth-intrinsics -fsyntax-only -ferror-limit 1 -verify -std=c++03 %s
3+
// RUN: %clang_cc1 -fsyntax-only -ferror-limit 1 -verify -std=c++03 %s
4+
5+
/// Force two errors so we hit the error limit leading to skip of template instantiation
6+
# "" // expected-error {{invalid preprocessing directive}}
7+
# ""
8+
// expected-error@* {{too many errors emitted}}
9+
10+
template <typename>
11+
struct a {};
12+
struct test_polymorphic {
13+
virtual ~test_polymorphic();
14+
a<int> field;
15+
};
16+
static_assert(__is_trivially_relocatable(test_polymorphic));
17+
18+
struct test_struct {
19+
test_struct(int) {}
20+
void test_instantiate() {
21+
test_struct d(0);
22+
}
23+
void test_type_trait_query() {
24+
__is_trivially_relocatable(test_struct);
25+
}
26+
a<int> e;
27+
};
28+
29+
struct test_struct2 {
30+
test_struct member;
31+
void test() {
32+
test_struct2 t{.member = {0}};
33+
}
34+
};
35+
36+
struct test_subclass : test_struct {
37+
test_subclass() : test_struct(0) {
38+
}
39+
40+
void test_subclass_instantiation() {
41+
test_subclass subclass{};
42+
}
43+
void test_subclass_type_trait_query() {
44+
__is_trivially_relocatable(test_subclass);
45+
}
46+
};

0 commit comments

Comments
 (0)