Skip to content

Commit c95c9dd

Browse files
ahatanakahatanaka
authored andcommitted
Address review comments
1 parent ae8a37e commit c95c9dd

File tree

14 files changed

+59
-37
lines changed

14 files changed

+59
-37
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,9 @@ def warn_pragma_unroll_cuda_value_in_parens : Warning<
17101710
"argument to '#pragma unroll' should not be in parentheses in CUDA C/C++">,
17111711
InGroup<CudaCompat>;
17121712

1713+
def err_ptrauth_qualifier_bad_arg_count : Error<
1714+
"'__ptrauth' qualifier must take between 1 and 3 arguments">;
1715+
17131716
def warn_cuda_attr_lambda_position : Warning<
17141717
"nvcc does not allow '__%0__' to appear after the parameter list in lambdas">,
17151718
InGroup<CudaCompat>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,6 @@ def err_ptrauth_qualifier_nonpointer : Error<
989989
"'__ptrauth' qualifier only applies to pointer types; %0 is invalid">;
990990
def err_ptrauth_qualifier_redundant : Error<
991991
"type %0 is already %1-qualified">;
992-
def err_ptrauth_qualifier_bad_arg_count : Error<
993-
"'__ptrauth' qualifier must take between 1 and 3 arguments">;
994992
def err_ptrauth_arg_not_ice : Error<
995993
"argument to '__ptrauth' must be an integer constant expression">;
996994
def err_ptrauth_address_discrimination_invalid : Error<

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
107107
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
108108
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
109109
FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
110-
FEATURE(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
110+
EXTENSION(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
111111
FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
112112
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
113113
FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtrAddressDiscrimination)

clang/lib/Parse/ParseDecl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ void Parser::DistributeCLateParsedAttrs(Decl *Dcl,
34053405
/// ('__ptrauth') '(' constant-expression
34063406
/// (',' constant-expression)[opt]
34073407
/// (',' constant-expression)[opt] ')'
3408-
void Parser::ParsePtrauthQualifier(ParsedAttributes &attrs) {
3408+
void Parser::ParsePtrauthQualifier(ParsedAttributes &Attrs) {
34093409
assert(Tok.is(tok::kw___ptrauth));
34103410

34113411
IdentifierInfo *KwName = Tok.getIdentifierInfo();
@@ -3428,7 +3428,12 @@ void Parser::ParsePtrauthQualifier(ParsedAttributes &attrs) {
34283428
T.consumeClose();
34293429
SourceLocation EndLoc = T.getCloseLocation();
34303430

3431-
attrs.addNew(KwName, SourceRange(KwLoc, EndLoc),
3431+
if (ArgExprs.empty() || ArgExprs.size() > 3) {
3432+
Diag(KwLoc, diag::err_ptrauth_qualifier_bad_arg_count);
3433+
return;
3434+
}
3435+
3436+
Attrs.addNew(KwName, SourceRange(KwLoc, EndLoc),
34323437
/*scope*/ nullptr, SourceLocation(), ArgExprs.data(),
34333438
ArgExprs.size(),
34343439
ParsedAttr::Form::Keyword(/*IsAlignAs=*/false,

clang/lib/Sema/SemaCast.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ namespace {
7272
// Preceding an expression by a parenthesized type name converts the
7373
// value of the expression to the unqualified, non-atomic version of
7474
// the named type.
75+
// Don't drop __ptrauth qualifiers. We want to treat casting to a
76+
// __ptrauth-qualified type as an error instead of implicitly ignoring
77+
// the qualifier.
7578
if (!S.Context.getLangOpts().ObjC && !DestType->isRecordType() &&
7679
!DestType->isArrayType() && !DestType.getPointerAuth()) {
7780
DestType = DestType.getAtomicUnqualifiedType();

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,18 +1577,12 @@ bool Sema::checkPointerAuthDiscriminatorArg(Expr *Arg,
15771577
};
15781578

15791579
if (*Result < 0 || *Result > Max) {
1580-
llvm::SmallString<32> Value;
1581-
{
1582-
llvm::raw_svector_ostream str(Value);
1583-
str << *Result;
1584-
}
1585-
15861580
if (IsAddrDiscArg)
15871581
Diag(Arg->getExprLoc(), diag::err_ptrauth_address_discrimination_invalid)
1588-
<< Value;
1582+
<< Result->getExtValue();
15891583
else
15901584
Diag(Arg->getExprLoc(), diag::err_ptrauth_extra_discriminator_invalid)
1591-
<< Value << Max;
1585+
<< Result->getExtValue() << Max;
15921586

15931587
return false;
15941588
};

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19379,10 +19379,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1937919379
} else if (FT.getQualifiers().getObjCLifetime() == Qualifiers::OCL_Weak) {
1938019380
Record->setArgPassingRestrictions(
1938119381
RecordArgPassingKind::CanNeverPassInRegs);
19382-
} else if (PointerAuthQualifier Q = FT.getPointerAuth()) {
19383-
if (Q.isAddressDiscriminated())
19384-
Record->setArgPassingRestrictions(
19385-
RecordArgPassingKind::CanNeverPassInRegs);
19382+
} else if (PointerAuthQualifier Q = FT.getPointerAuth();
19383+
Q && Q.isAddressDiscriminated()) {
19384+
Record->setArgPassingRestrictions(
19385+
RecordArgPassingKind::CanNeverPassInRegs);
1938619386
}
1938719387
}
1938819388

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9363,7 +9363,7 @@ struct SpecialMemberDeletionInfo
93639363

93649364
bool shouldDeleteForVariantObjCPtrMember(FieldDecl *FD, QualType FieldType);
93659365

9366-
bool shouldDeleteForVariantPtrAuthMember(FieldDecl *FD, QualType FieldType);
9366+
bool shouldDeleteForVariantPtrAuthMember(const FieldDecl *FD);
93679367

93689368
bool visitBase(CXXBaseSpecifier *Base) { return shouldDeleteForBase(Base); }
93699369
bool visitField(FieldDecl *Field) { return shouldDeleteForField(Field); }
@@ -9534,7 +9534,8 @@ bool SpecialMemberDeletionInfo::shouldDeleteForVariantObjCPtrMember(
95349534
}
95359535

95369536
bool SpecialMemberDeletionInfo::shouldDeleteForVariantPtrAuthMember(
9537-
FieldDecl *FD, QualType FieldType) {
9537+
const FieldDecl *FD) {
9538+
QualType FieldType = S.Context.getBaseElementType(FD->getType());
95389539
// Copy/move constructors/assignment operators are deleted if the field has an
95399540
// address-discriminated ptrauth qualifier.
95409541
PointerAuthQualifier Q = FieldType.getPointerAuth();
@@ -9594,7 +9595,7 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
95949595
if (inUnion() && shouldDeleteForVariantObjCPtrMember(FD, FieldType))
95959596
return true;
95969597

9597-
if (inUnion() && shouldDeleteForVariantPtrAuthMember(FD, FieldType))
9598+
if (inUnion() && shouldDeleteForVariantPtrAuthMember(FD))
95989599
return true;
95999600

96009601
if (CSM == CXXSpecialMemberKind::DefaultConstructor) {
@@ -9660,7 +9661,7 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
96609661
if (shouldDeleteForVariantObjCPtrMember(&*UI, UnionFieldType))
96619662
return true;
96629663

9663-
if (shouldDeleteForVariantPtrAuthMember(&*UI, UnionFieldType))
9664+
if (shouldDeleteForVariantPtrAuthMember(&*UI))
96649665
return true;
96659666

96669667
if (!UnionFieldType.isConstQualified())

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8413,12 +8413,9 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
84138413
/// Handle the __ptrauth qualifier.
84148414
static void HandlePtrAuthQualifier(ASTContext &Ctx, QualType &T,
84158415
const ParsedAttr &Attr, Sema &S) {
8416-
if (Attr.getNumArgs() < 1 || Attr.getNumArgs() > 3) {
8417-
S.Diag(Attr.getLoc(), diag::err_ptrauth_qualifier_bad_arg_count);
8418-
Attr.setInvalid();
8419-
return;
8420-
}
84218416

8417+
assert((Attr.getNumArgs() > 0 && Attr.getNumArgs() <= 3) &&
8418+
"__ptrauth qualifier takes between 1 and 3 arguments");
84228419
Expr *KeyArg = Attr.getArgAsExpr(0);
84238420
Expr *IsAddressDiscriminatedArg =
84248421
Attr.getNumArgs() >= 2 ? Attr.getArgAsExpr(1) : nullptr;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s
2+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s
3+
4+
#if __aarch64__
5+
#define VALID_DATA_KEY 2
6+
#else
7+
#error Provide these constants if you port this test
8+
#endif
9+
10+
int * __ptrauth(VALID_DATA_KEY) valid0;
11+
12+
typedef int *intp;
13+
14+
int nonConstantGlobal = 5;
15+
16+
__ptrauth int invalid0; // expected-error{{expected '('}}
17+
__ptrauth() int invalid1; // expected-error{{expected expression}}
18+
int * __ptrauth(VALID_DATA_KEY, 1, 1000, 12) invalid12; // expected-error{{qualifier must take between 1 and 3 arguments}}

0 commit comments

Comments
 (0)