Skip to content

Don't drop ptrauth qualifiers when constructing C++ composite types #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2020
Merged
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
10 changes: 10 additions & 0 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6208,6 +6208,7 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
// exists.
SmallVector<unsigned, 4> QualifierUnion;
SmallVector<std::pair<const Type *, const Type *>, 4> MemberOfClass;
SmallVector<PointerAuthQualifier, 4> PtrAuthQualifier;
QualType Composite1 = T1;
QualType Composite2 = T2;
unsigned NeedConstBefore = 0;
Expand All @@ -6226,6 +6227,9 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
QualifierUnion.push_back(
Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
MemberOfClass.push_back(std::make_pair(nullptr, nullptr));
PtrAuthQualifier.resize(PtrAuthQualifier.size() + 1);
if (Composite1.getPointerAuth() == Composite2.getPointerAuth())
PtrAuthQualifier.back() = Composite1.getPointerAuth();
continue;
}

Expand All @@ -6244,6 +6248,9 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
MemberOfClass.push_back(std::make_pair(MemPtr1->getClass(),
MemPtr2->getClass()));
PtrAuthQualifier.resize(PtrAuthQualifier.size() + 1);
if (Composite1.getPointerAuth() == Composite2.getPointerAuth())
PtrAuthQualifier.back() = Composite1.getPointerAuth();
continue;
}

Expand Down Expand Up @@ -6299,8 +6306,11 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,

// Rewrap the composites as pointers or member pointers with the union CVRs.
auto MOC = MemberOfClass.rbegin();
auto PtrAuthQualIt = PtrAuthQualifier.rbegin();
for (unsigned CVR : llvm::reverse(QualifierUnion)) {
Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
if (PointerAuthQualifier PtrAuthQual = *PtrAuthQualIt++)
Quals.setPointerAuth(PtrAuthQual);
auto Classes = *MOC++;
if (Classes.first && Classes.second) {
// Rebuild member pointer type
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/ptrauth-qualifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ namespace test_union {
}
}

bool test_composite_type0(bool c, int * AQ * a0, int * AQ * a1) {
auto t = c ? a0 : a1;
return a0 == a1;
}

bool test_composite_type1(bool c, int * AQ * a0, int * AQ2 * a1) {
auto t = c ? a0 : a1; // expected-error {{incompatible operand types ('int *__ptrauth(1,1,50) *' and 'int *__ptrauth(1,1,51) *')}}
return a0 == a1; // expected-error {{comparison of distinct pointer types ('int *__ptrauth(1,1,50) *' and 'int *__ptrauth(1,1,51) *')}}
}

void test_bad_call_diag(void *AQ* ptr); // expected-note{{candidate function not viable: 1st argument ('void *__ptrauth(1,1,51) *') has __ptrauth(1,1,51) qualifier, but parameter has __ptrauth(1,1,50) qualifier}} expected-note{{candidate function not viable: 1st argument ('void **') has no ptrauth qualifier, but parameter has __ptrauth(1,1,50) qualifier}}
void test_bad_call_diag2(void ** ptr); // expected-note{{1st argument ('void *__ptrauth(1,1,50) *') has __ptrauth(1,1,50) qualifier, but parameter has no ptrauth qualifier}}

Expand Down