Skip to content

Commit d64227d

Browse files
committed
Address review comments
1 parent a760923 commit d64227d

File tree

12 files changed

+102
-99
lines changed

12 files changed

+102
-99
lines changed

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,8 @@ class QualType {
14681468
}
14691469

14701470
bool hasAddressDiscriminatedPointerAuth() const {
1471-
if (PointerAuthQualifier ptrauth = getPointerAuth())
1472-
return ptrauth.isAddressDiscriminated();
1471+
if (PointerAuthQualifier PtrAuth = getPointerAuth())
1472+
return PtrAuth.isAddressDiscriminated();
14731473
return false;
14741474
}
14751475

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,8 +1781,8 @@ Valid key names for the target are defined in ``<ptrauth.h>``.
17811781
The second argument to ``__ptrauth`` is a flag (0 or 1) specifying whether
17821782
the object should use address discrimination.
17831783

1784-
The third argument to ``__ptrauth`` is a small non-negative integer
1785-
which allows additional discrimination between objects.
1784+
The third argument to ``__ptrauth`` is a 16-bit non-negative integer which
1785+
allows additional discrimination between objects.
17861786
}];
17871787
}
17881788

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,16 +1734,16 @@ static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type) {
17341734
/// for instance if a block or lambda or a member of a local class uses a
17351735
/// const int variable or constexpr variable from an enclosing function.
17361736
CodeGenFunction::ConstantEmission
1737-
CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
1738-
ValueDecl *value = refExpr->getDecl();
1737+
CodeGenFunction::tryEmitAsConstant(const DeclRefExpr *RefExpr) {
1738+
const ValueDecl *Value = RefExpr->getDecl();
17391739

17401740
// The value needs to be an enum constant or a constant variable.
17411741
ConstantEmissionKind CEK;
1742-
if (isa<ParmVarDecl>(value)) {
1742+
if (isa<ParmVarDecl>(Value)) {
17431743
CEK = CEK_None;
1744-
} else if (auto *var = dyn_cast<VarDecl>(value)) {
1744+
} else if (auto *var = dyn_cast<VarDecl>(Value)) {
17451745
CEK = checkVarTypeForConstantEmission(var->getType());
1746-
} else if (isa<EnumConstantDecl>(value)) {
1746+
} else if (isa<EnumConstantDecl>(Value)) {
17471747
CEK = CEK_AsValueOnly;
17481748
} else {
17491749
CEK = CEK_None;
@@ -1756,15 +1756,15 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
17561756

17571757
// It's best to evaluate all the way as an r-value if that's permitted.
17581758
if (CEK != CEK_AsReferenceOnly &&
1759-
refExpr->EvaluateAsRValue(result, getContext())) {
1759+
RefExpr->EvaluateAsRValue(result, getContext())) {
17601760
resultIsReference = false;
1761-
resultType = refExpr->getType().getUnqualifiedType();
1761+
resultType = RefExpr->getType().getUnqualifiedType();
17621762

17631763
// Otherwise, try to evaluate as an l-value.
17641764
} else if (CEK != CEK_AsValueOnly &&
1765-
refExpr->EvaluateAsLValue(result, getContext())) {
1765+
RefExpr->EvaluateAsLValue(result, getContext())) {
17661766
resultIsReference = true;
1767-
resultType = value->getType();
1767+
resultType = Value->getType();
17681768

17691769
// Failure.
17701770
} else {
@@ -1783,7 +1783,7 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
17831783
// accessible on device. The DRE of the captured reference variable has to be
17841784
// loaded from captures.
17851785
if (CGM.getLangOpts().CUDAIsDevice && result.Val.isLValue() &&
1786-
refExpr->refersToEnclosingVariableOrCapture()) {
1786+
RefExpr->refersToEnclosingVariableOrCapture()) {
17871787
auto *MD = dyn_cast_or_null<CXXMethodDecl>(CurCodeDecl);
17881788
if (MD && MD->getParent()->isLambda() &&
17891789
MD->getOverloadedOperator() == OO_Call) {
@@ -1799,17 +1799,17 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
17991799
}
18001800

18011801
// Emit as a constant.
1802-
auto C = ConstantEmitter(*this).emitAbstract(refExpr->getLocation(),
1802+
auto C = ConstantEmitter(*this).emitAbstract(RefExpr->getLocation(),
18031803
result.Val, resultType);
18041804

18051805
// Make sure we emit a debug reference to the global variable.
18061806
// This should probably fire even for
1807-
if (isa<VarDecl>(value)) {
1808-
if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value)))
1809-
EmitDeclRefExprDbgValue(refExpr, result.Val);
1807+
if (isa<VarDecl>(Value)) {
1808+
if (!getContext().DeclMustBeEmitted(cast<VarDecl>(Value)))
1809+
EmitDeclRefExprDbgValue(RefExpr, result.Val);
18101810
} else {
1811-
assert(isa<EnumConstantDecl>(value));
1812-
EmitDeclRefExprDbgValue(refExpr, result.Val);
1811+
assert(isa<EnumConstantDecl>(Value));
1812+
EmitDeclRefExprDbgValue(RefExpr, result.Val);
18131813
}
18141814

18151815
// If we emitted a reference constant, we need to dereference that.
@@ -2201,8 +2201,8 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, SourceLocation Loc) {
22012201
// Load from __ptrauth.
22022202
if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) {
22032203
LV.getQuals().removePointerAuth();
2204-
auto value = EmitLoadOfLValue(LV, Loc).getScalarVal();
2205-
return RValue::get(EmitPointerAuthUnqualify(PtrAuth, value, LV.getType(),
2204+
auto Value = EmitLoadOfLValue(LV, Loc).getScalarVal();
2205+
return RValue::get(EmitPointerAuthUnqualify(PtrAuth, Value, LV.getType(),
22062206
LV.getAddress(),
22072207
/*known nonnull*/ false));
22082208
}
@@ -5582,8 +5582,8 @@ CGCallee CodeGenFunction::EmitCallee(const Expr *E) {
55825582
// Try to remember the original __ptrauth qualifier for loads of
55835583
// function pointers.
55845584
if (ICE->getCastKind() == CK_LValueToRValue) {
5585-
auto *SubExpr = ICE->getSubExpr();
5586-
if (auto *PtrType = SubExpr->getType()->getAs<PointerType>()) {
5585+
const auto *SubExpr = ICE->getSubExpr();
5586+
if (const auto *PtrType = SubExpr->getType()->getAs<PointerType>()) {
55875587
auto Result = EmitOrigPointerRValue(E);
55885588

55895589
QualType FunctionType = PtrType->getPointeeType();

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,15 +2203,14 @@ static bool isDeclRefKnownNonNull(CodeGenFunction &CGF, const ValueDecl *D) {
22032203
static bool isLValueKnownNonNull(CodeGenFunction &CGF, const Expr *E) {
22042204
E = E->IgnoreParens();
22052205

2206-
if (auto *UO = dyn_cast<UnaryOperator>(E)) {
2207-
if (UO->getOpcode() == UO_Deref) {
2206+
if (const auto *UO = dyn_cast<UnaryOperator>(E))
2207+
if (UO->getOpcode() == UO_Deref)
22082208
return CGF.isPointerKnownNonNull(UO->getSubExpr());
2209-
}
2210-
}
22112209

2212-
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
2210+
if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
22132211
return isDeclRefKnownNonNull(CGF, DRE->getDecl());
2214-
} else if (auto *ME = dyn_cast<MemberExpr>(E)) {
2212+
2213+
if (const auto *ME = dyn_cast<MemberExpr>(E)) {
22152214
if (isa<FieldDecl>(ME->getMemberDecl()))
22162215
return true;
22172216
return isDeclRefKnownNonNull(CGF, ME->getMemberDecl());
@@ -2230,18 +2229,14 @@ bool CodeGenFunction::isPointerKnownNonNull(const Expr *E) {
22302229
if (isa<CXXThisExpr>(E))
22312230
return true;
22322231

2233-
if (auto *UO = dyn_cast<UnaryOperator>(E)) {
2234-
if (UO->getOpcode() == UO_AddrOf) {
2232+
if (const auto *UO = dyn_cast<UnaryOperator>(E))
2233+
if (UO->getOpcode() == UO_AddrOf)
22352234
return isLValueKnownNonNull(*this, UO->getSubExpr());
2236-
}
2237-
}
22382235

2239-
if (auto *CE = dyn_cast<CastExpr>(E)) {
2236+
if (const auto *CE = dyn_cast<CastExpr>(E))
22402237
if (CE->getCastKind() == CK_FunctionToPointerDecay ||
2241-
CE->getCastKind() == CK_ArrayToPointerDecay) {
2238+
CE->getCastKind() == CK_ArrayToPointerDecay)
22422239
return isLValueKnownNonNull(*this, CE->getSubExpr());
2243-
}
2244-
}
22452240

22462241
// Maybe honor __nonnull?
22472242

clang/lib/CodeGen/CGPointerAuth.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,10 @@ emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV,
198198
SourceLocation Loc) {
199199
auto *Value = CGF.EmitLoadOfScalar(LV, Loc);
200200
CGPointerAuthInfo AuthInfo;
201-
if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth()) {
201+
if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth())
202202
AuthInfo = CGF.EmitPointerAuthInfo(PtrAuth, LV.getAddress());
203-
} else {
203+
else
204204
AuthInfo = getPointerAuthInfoForType(CGF.CGM, LV.getType());
205-
}
206205
return {Value, AuthInfo};
207206
}
208207

@@ -213,12 +212,12 @@ CodeGenFunction::EmitOrigPointerRValue(const Expr *E) {
213212
assert(E->getType()->isSignableType());
214213

215214
E = E->IgnoreParens();
216-
if (auto *Load = dyn_cast<ImplicitCastExpr>(E)) {
215+
if (const auto *Load = dyn_cast<ImplicitCastExpr>(E)) {
217216
if (Load->getCastKind() == CK_LValueToRValue) {
218217
E = Load->getSubExpr()->IgnoreParens();
219218

220219
// We're semantically required to not emit loads of certain DREs naively.
221-
if (auto *RefExpr = dyn_cast<DeclRefExpr>(const_cast<Expr *>(E))) {
220+
if (const auto *RefExpr = dyn_cast<DeclRefExpr>(E)) {
222221
if (auto Result = tryEmitAsConstant(RefExpr)) {
223222
// Fold away a use of an intermediate variable.
224223
if (!Result.isReference())

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,10 +4313,10 @@ class CodeGenFunction : public CodeGenTypeCache {
43134313
}
43144314

43154315
bool isReference() const { return ValueAndIsReference.getInt(); }
4316-
LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const {
4316+
LValue getReferenceLValue(CodeGenFunction &CGF, const Expr *RefExpr) const {
43174317
assert(isReference());
43184318
return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
4319-
refExpr->getType());
4319+
RefExpr->getType());
43204320
}
43214321

43224322
llvm::Constant *getValue() const {
@@ -4325,7 +4325,7 @@ class CodeGenFunction : public CodeGenTypeCache {
43254325
}
43264326
};
43274327

4328-
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr);
4328+
ConstantEmission tryEmitAsConstant(const DeclRefExpr *RefExpr);
43294329
ConstantEmission tryEmitAsConstant(const MemberExpr *ME);
43304330
llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E);
43314331

clang/lib/Sema/SemaType.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8230,24 +8230,24 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
82308230

82318231
/// Handle the __ptrauth qualifier.
82328232
static void HandlePtrAuthQualifier(ASTContext &Ctx, QualType &T,
8233-
const ParsedAttr &attr, Sema &S) {
8234-
auto AttributeName = attr.getAttrName()->getName();
8235-
if (attr.getNumArgs() < 1 || attr.getNumArgs() > 3) {
8236-
S.Diag(attr.getLoc(), diag::err_ptrauth_qualifier_bad_arg_count)
8233+
const ParsedAttr &Attr, Sema &S) {
8234+
auto AttributeName = Attr.getAttrName()->getName();
8235+
if (Attr.getNumArgs() < 1 || Attr.getNumArgs() > 3) {
8236+
S.Diag(Attr.getLoc(), diag::err_ptrauth_qualifier_bad_arg_count)
82378237
<< AttributeName;
8238-
attr.setInvalid();
8238+
Attr.setInvalid();
82398239
return;
82408240
}
82418241

8242-
Expr *KeyArg = attr.getArgAsExpr(0);
8242+
Expr *KeyArg = Attr.getArgAsExpr(0);
82438243
Expr *IsAddressDiscriminatedArg =
8244-
attr.getNumArgs() >= 2 ? attr.getArgAsExpr(1) : nullptr;
8244+
Attr.getNumArgs() >= 2 ? Attr.getArgAsExpr(1) : nullptr;
82458245
Expr *ExtraDiscriminatorArg =
8246-
attr.getNumArgs() >= 3 ? attr.getArgAsExpr(2) : nullptr;
8246+
Attr.getNumArgs() >= 3 ? Attr.getArgAsExpr(2) : nullptr;
82478247

82488248
unsigned Key;
82498249
if (S.checkConstantPointerAuthKey(KeyArg, Key)) {
8250-
attr.setInvalid();
8250+
Attr.setInvalid();
82518251
return;
82528252
}
82538253
assert(Key <= PointerAuthQualifier::MaxKey && "ptrauth key is out of range");
@@ -8261,26 +8261,26 @@ static void HandlePtrAuthQualifier(ASTContext &Ctx, QualType &T,
82618261
ExtraDiscriminatorArg, Sema::PADAK_ExtraDiscPtrAuth, ExtraDiscriminator);
82628262

82638263
if (IsInvalid) {
8264-
attr.setInvalid();
8264+
Attr.setInvalid();
82658265
return;
82668266
}
82678267

82688268
if (!T->isSignableType() && !T->isDependentType()) {
8269-
S.Diag(attr.getLoc(), diag::err_ptrauth_qualifier_nonpointer) << T;
8270-
attr.setInvalid();
8269+
S.Diag(Attr.getLoc(), diag::err_ptrauth_qualifier_nonpointer) << T;
8270+
Attr.setInvalid();
82718271
return;
82728272
}
82738273

82748274
if (T.getPointerAuth()) {
8275-
S.Diag(attr.getLoc(), diag::err_ptrauth_qualifier_redundant)
8276-
<< T << attr.getAttrName()->getName();
8277-
attr.setInvalid();
8275+
S.Diag(Attr.getLoc(), diag::err_ptrauth_qualifier_redundant)
8276+
<< T << Attr.getAttrName()->getName();
8277+
Attr.setInvalid();
82788278
return;
82798279
}
82808280

82818281
if (!S.getLangOpts().PointerAuthIntrinsics) {
8282-
S.Diag(attr.getLoc(), diag::err_ptrauth_disabled) << attr.getRange();
8283-
attr.setInvalid();
8282+
S.Diag(Attr.getLoc(), diag::err_ptrauth_disabled) << Attr.getRange();
8283+
Attr.setInvalid();
82848284
return;
82858285
}
82868286

clang/test/CodeGen/ptrauth-debuginfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ struct A {
1919
struct A *createA(void);
2020

2121
void f() {
22-
__block struct A *__ptrauth(1, 1, 1236) ptr = createA();
22+
__block struct A *__ptrauth(0, 1, 1236) ptr = createA();
2323
^{
2424
(void)ptr->value;
2525
}();
2626
}
2727
// CHECK: !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type,
28-
// CHECK-SAME: ptrAuthKey: 1,
28+
// CHECK-NOT: ptrAuthKey
2929
// CHECK-SAME: ptrAuthIsAddressDiscriminated: true,
3030
// CHECK-SAME: ptrAuthExtraDiscriminator: 1236,
3131
// CHECK-SAME: ptrAuthIsaPointer: false,

clang/test/CodeGen/ptrauth-qualifier.c renamed to clang/test/CodeGen/ptrauth-qualifier-const-init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s
22

3-
#include <ptrauth.h>
4-
53
// Constant initializers for data pointers.
64
extern int external_int;
75

0 commit comments

Comments
 (0)