Skip to content

Commit f4efa06

Browse files
kovdan01rjmccallahmedbougacha
authored
[PAC][clang] Define PointerAuthQualifier and PointerAuthenticationMode (#84384)
This brings declarations of `PointerAuthQualifier` class and `PointerAuthenticationMode` enum and related functions required for PAuth support in lldb (see #84387) from downstream Apple's code. See #84387 for tests as well. Co-authored-by: Ahmed Bougacha <[email protected]> Co-authored-by: John McCall <[email protected]> --------- Co-authored-by: John McCall <[email protected]> Co-authored-by: Ahmed Bougacha <[email protected]>
1 parent 7840fa9 commit f4efa06

File tree

7 files changed

+283
-36
lines changed

7 files changed

+283
-36
lines changed

clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,8 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
967967
// Get out the qualifiers of the original type. This will always be
968968
// re-applied to the WorkType to ensure it is the same qualification as the
969969
// original From was.
970-
auto QualifiersToApply = From.split().Quals.getAsOpaqueValue();
970+
auto FastQualifiersToApply = static_cast<unsigned>(
971+
From.split().Quals.getAsOpaqueValue() & Qualifiers::FastMask);
971972

972973
// LValue->RValue is irrelevant for the check, because it is a thing to be
973974
// done at a call site, and will be performed if need be performed.
@@ -993,7 +994,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
993994
// "const double -> double".
994995
LLVM_DEBUG(llvm::dbgs()
995996
<< "--- approximateStdConv. Conversion between numerics.\n");
996-
WorkType = QualType{ToBuiltin, QualifiersToApply};
997+
WorkType = QualType{ToBuiltin, FastQualifiersToApply};
997998
}
998999

9991000
const auto *FromEnum = WorkType->getAs<EnumType>();
@@ -1002,7 +1003,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
10021003
// Unscoped enumerations (or enumerations in C) convert to numerics.
10031004
LLVM_DEBUG(llvm::dbgs()
10041005
<< "--- approximateStdConv. Unscoped enum to numeric.\n");
1005-
WorkType = QualType{ToBuiltin, QualifiersToApply};
1006+
WorkType = QualType{ToBuiltin, FastQualifiersToApply};
10061007
} else if (FromNumeric && ToEnum && ToEnum->isUnscopedEnumerationType()) {
10071008
// Numeric types convert to enumerations only in C.
10081009
if (Ctx.getLangOpts().CPlusPlus) {
@@ -1013,7 +1014,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
10131014

10141015
LLVM_DEBUG(llvm::dbgs()
10151016
<< "--- approximateStdConv. Numeric to unscoped enum.\n");
1016-
WorkType = QualType{ToEnum, QualifiersToApply};
1017+
WorkType = QualType{ToEnum, FastQualifiersToApply};
10171018
}
10181019

10191020
// Check for pointer conversions.
@@ -1022,14 +1023,14 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
10221023
if (FromPtr && ToPtr) {
10231024
if (ToPtr->isVoidPointerType()) {
10241025
LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. To void pointer.\n");
1025-
WorkType = QualType{ToPtr, QualifiersToApply};
1026+
WorkType = QualType{ToPtr, FastQualifiersToApply};
10261027
}
10271028

10281029
const auto *FromRecordPtr = FromPtr->getPointeeCXXRecordDecl();
10291030
const auto *ToRecordPtr = ToPtr->getPointeeCXXRecordDecl();
10301031
if (isDerivedToBase(FromRecordPtr, ToRecordPtr)) {
10311032
LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. Derived* to Base*\n");
1032-
WorkType = QualType{ToPtr, QualifiersToApply};
1033+
WorkType = QualType{ToPtr, FastQualifiersToApply};
10331034
}
10341035
}
10351036

@@ -1039,7 +1040,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
10391040
const auto *ToRecord = To->getAsCXXRecordDecl();
10401041
if (isDerivedToBase(FromRecord, ToRecord)) {
10411042
LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. Derived To Base.\n");
1042-
WorkType = QualType{ToRecord->getTypeForDecl(), QualifiersToApply};
1043+
WorkType = QualType{ToRecord->getTypeForDecl(), FastQualifiersToApply};
10431044
}
10441045

10451046
if (Ctx.getLangOpts().CPlusPlus17 && FromPtr && ToPtr) {
@@ -1054,7 +1055,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
10541055
!ToFunctionPtr->hasNoexceptExceptionSpec()) {
10551056
LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. noexcept function "
10561057
"pointer to non-noexcept.\n");
1057-
WorkType = QualType{ToPtr, QualifiersToApply};
1058+
WorkType = QualType{ToPtr, FastQualifiersToApply};
10581059
}
10591060
}
10601061

clang/include/clang/AST/ASTContext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,16 @@ class ASTContext : public RefCountedBase<ASTContext> {
21972197
return getQualifiedType(type.getUnqualifiedType(), Qs);
21982198
}
21992199

2200+
/// \brief Return a type with the given __ptrauth qualifier.
2201+
QualType getPointerAuthType(QualType Ty, PointerAuthQualifier PointerAuth) {
2202+
assert(!Ty.getPointerAuth());
2203+
assert(PointerAuth);
2204+
2205+
Qualifiers Qs;
2206+
Qs.setPointerAuth(PointerAuth);
2207+
return getQualifiedType(Ty, Qs);
2208+
}
2209+
22002210
unsigned char getFixedPointScale(QualType Ty) const;
22012211
unsigned char getFixedPointIBits(QualType Ty) const;
22022212
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const;

clang/include/clang/AST/AbstractBasicReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
213213
}
214214

215215
Qualifiers readQualifiers() {
216-
static_assert(sizeof(Qualifiers().getAsOpaqueValue()) <= sizeof(uint32_t),
216+
static_assert(sizeof(Qualifiers().getAsOpaqueValue()) <= sizeof(uint64_t),
217217
"update this if the value size changes");
218-
uint32_t value = asImpl().readUInt32();
218+
uint64_t value = asImpl().readUInt64();
219219
return Qualifiers::fromOpaqueValue(value);
220220
}
221221

clang/include/clang/AST/AbstractBasicWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
196196
}
197197

198198
void writeQualifiers(Qualifiers value) {
199-
static_assert(sizeof(value.getAsOpaqueValue()) <= sizeof(uint32_t),
199+
static_assert(sizeof(value.getAsOpaqueValue()) <= sizeof(uint64_t),
200200
"update this if the value size changes");
201-
asImpl().writeUInt32(value.getAsOpaqueValue());
201+
asImpl().writeUInt64(value.getAsOpaqueValue());
202202
}
203203

204204
void writeExceptionSpecInfo(

0 commit comments

Comments
 (0)