Skip to content

Commit c1dd3a0

Browse files
author
git apple-llvm automerger
committed
Merge commit '53556b0787b2' from apple/stable/20200108 into swift/master
2 parents 5e44138 + 53556b0 commit c1dd3a0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6208,6 +6208,7 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
62086208
// exists.
62096209
SmallVector<unsigned, 4> QualifierUnion;
62106210
SmallVector<std::pair<const Type *, const Type *>, 4> MemberOfClass;
6211+
SmallVector<PointerAuthQualifier, 4> PtrAuthQualifier;
62116212
QualType Composite1 = T1;
62126213
QualType Composite2 = T2;
62136214
unsigned NeedConstBefore = 0;
@@ -6226,6 +6227,9 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
62266227
QualifierUnion.push_back(
62276228
Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
62286229
MemberOfClass.push_back(std::make_pair(nullptr, nullptr));
6230+
PtrAuthQualifier.resize(PtrAuthQualifier.size() + 1);
6231+
if (Composite1.getPointerAuth() == Composite2.getPointerAuth())
6232+
PtrAuthQualifier.back() = Composite1.getPointerAuth();
62296233
continue;
62306234
}
62316235

@@ -6244,6 +6248,9 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
62446248
Composite1.getCVRQualifiers() | Composite2.getCVRQualifiers());
62456249
MemberOfClass.push_back(std::make_pair(MemPtr1->getClass(),
62466250
MemPtr2->getClass()));
6251+
PtrAuthQualifier.resize(PtrAuthQualifier.size() + 1);
6252+
if (Composite1.getPointerAuth() == Composite2.getPointerAuth())
6253+
PtrAuthQualifier.back() = Composite1.getPointerAuth();
62476254
continue;
62486255
}
62496256

@@ -6299,8 +6306,11 @@ QualType Sema::FindCompositePointerType(SourceLocation Loc,
62996306

63006307
// Rewrap the composites as pointers or member pointers with the union CVRs.
63016308
auto MOC = MemberOfClass.rbegin();
6309+
auto PtrAuthQualIt = PtrAuthQualifier.rbegin();
63026310
for (unsigned CVR : llvm::reverse(QualifierUnion)) {
63036311
Qualifiers Quals = Qualifiers::fromCVRMask(CVR);
6312+
if (PointerAuthQualifier PtrAuthQual = *PtrAuthQualIt++)
6313+
Quals.setPointerAuth(PtrAuthQual);
63046314
auto Classes = *MOC++;
63056315
if (Classes.first && Classes.second) {
63066316
// Rebuild member pointer type

clang/test/SemaCXX/ptrauth-qualifier.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ namespace test_union {
120120
}
121121
}
122122

123+
bool test_composite_type0(bool c, int * AQ * a0, int * AQ * a1) {
124+
auto t = c ? a0 : a1;
125+
return a0 == a1;
126+
}
127+
128+
bool test_composite_type1(bool c, int * AQ * a0, int * AQ2 * a1) {
129+
auto t = c ? a0 : a1; // expected-error {{incompatible operand types ('int *__ptrauth(1,1,50) *' and 'int *__ptrauth(1,1,51) *')}}
130+
return a0 == a1; // expected-error {{comparison of distinct pointer types ('int *__ptrauth(1,1,50) *' and 'int *__ptrauth(1,1,51) *')}}
131+
}
132+
123133
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}}
124134
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}}
125135

0 commit comments

Comments
 (0)