Skip to content

Commit dbbf6aa

Browse files
authored
Merge branch 'main' into freestanding-macro-attr-cleanup
2 parents d1716e6 + def44c5 commit dbbf6aa

39 files changed

+369
-44
lines changed

docs/SIL.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,6 +4522,7 @@ begin_access
45224522
sil-enforcement ::= static
45234523
sil-enforcement ::= dynamic
45244524
sil-enforcement ::= unsafe
4525+
sil-enforcement ::= signed
45254526
%1 = begin_access [read] [unknown] %0 : $*T
45264527
// %0 must be of $*T type.
45274528

@@ -4564,6 +4565,9 @@ runtime for the duration of its scope. This access may still conflict with an
45644565
outer access scope; therefore may still require dynamic enforcement at a single
45654566
point.
45664567

4568+
A ``signed`` access is for pointers that are signed in architectures that support
4569+
pointer signing.
4570+
45674571
A ``builtin`` access was emitted for a user-controlled Builtin (e.g. the
45684572
standard library's KeyPath access). Non-builtin accesses are auto-generated by
45694573
the compiler to enforce formal access that derives from the language. A

include/swift/AST/Attr.def.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ TYPE_ATTR(thin)
9292
TYPE_ATTR(thick)
9393

9494
// Declaration Attributes and Modifers
95-
// To add a new entry here, update https://github.com/apple/swift-syntax
95+
// To add a new entry here, update `utils/gyb_syntax_support/AttributeKinds.py`
9696
% for attr in DECL_ATTR_KINDS + DECL_MODIFIER_KINDS + DEPRECATED_MODIFIER_KINDS:
9797
% if type(attr) is ContextualDeclAttributeAlias:
9898
CONTEXTUAL_DECL_ATTR_ALIAS(${attr.name}, ${attr.class_name})

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5958,6 +5958,8 @@ class VarDecl : public AbstractStorageDecl {
59585958
});
59595959
}
59605960

5961+
clang::PointerAuthQualifier getPointerAuthQualifier() const;
5962+
59615963
// Implement isa/cast/dyncast/etc.
59625964
static bool classof(const Decl *D) {
59635965
return D->getKind() == DeclKind::Var || D->getKind() == DeclKind::Param;

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,9 +3863,6 @@ class AbstractClosureExpr : public DeclContext, public Expr {
38633863
/// Only valid when \c hasSingleExpressionBody() is true.
38643864
Expr *getSingleExpressionBody() const;
38653865

3866-
/// Whether this closure has a body
3867-
bool hasBody() const;
3868-
38693866
/// Returns the body of closures that have a body
38703867
/// returns nullptr if the closure doesn't have a body
38713868
BraceStmt *getBody() const;
@@ -4273,6 +4270,7 @@ class CaptureListExpr final : public Expr,
42734270
AbstractClosureExpr *closureBody)
42744271
: Expr(ExprKind::CaptureList, /*Implicit=*/false, Type()),
42754272
closureBody(closureBody) {
4273+
assert(closureBody);
42764274
Bits.CaptureListExpr.NumCaptures = captureList.size();
42774275
std::uninitialized_copy(captureList.begin(), captureList.end(),
42784276
getTrailingObjects<CaptureListEntry>());

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class SILOptions {
135135
/// temporaries for stack protection.
136136
bool EnableMoveInoutStackProtection = false;
137137

138+
/// Enables codegen support for clang imported ptrauth qualified field
139+
/// function pointers.
140+
bool EnableImportPtrauthFieldFunctionPointers = false;
141+
138142
/// Controls whether or not paranoid verification checks are run.
139143
bool VerifyAll = false;
140144

include/swift/Option/FrontendOptions.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,13 @@ def enable_move_inout_stack_protector :
11121112
Flag<["-"], "enable-move-inout-stack-protector">,
11131113
HelpText<"Enable the stack protector by moving values to temporaries">;
11141114

1115+
def enable_import_ptrauth_field_function_pointers :
1116+
Flag<["-"], "enable-import-ptrauth-field-function-pointers">,
1117+
HelpText<"Enable import of custom ptrauth qualified field function pointers">;
1118+
def disable_import_ptrauth_field_function_pointers :
1119+
Flag<["-"], "disable-import-ptrauth-field-function-pointers">,
1120+
HelpText<"Disable import of custom ptrauth qualified field function pointers">;
1121+
11151122
def enable_collocate_metadata_functions :
11161123
Flag<["-"], "enable-collocate-metadata-functions">,
11171124
HelpText<"Enable collocate metadata functions">;

include/swift/SIL/SILInstruction.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4446,8 +4446,13 @@ enum class SILAccessEnforcement : uint8_t {
44464446
/// behavior.
44474447
Unsafe,
44484448

4449+
/// Access to pointers that are signed via pointer authentication mechanishm.
4450+
/// Such pointers should be authenticated before read and signed before a
4451+
/// write. Optimizer should avoid promoting such accesses to values.
4452+
Signed,
4453+
44494454
// This enum is encoded.
4450-
Last = Unsafe
4455+
Last = Signed
44514456
};
44524457
StringRef getSILAccessEnforcementName(SILAccessEnforcement enforcement);
44534458

@@ -4520,9 +4525,9 @@ class BeginAccessInst
45204525
: BeginAccessBase(loc, accessKind, enforcement, noNestedConflict,
45214526
fromBuiltin, lvalue, lvalue->getType()) {
45224527

4523-
static_assert(unsigned(SILAccessKind::Last) < (1 << 2),
4528+
static_assert(unsigned(SILAccessKind::Last) < (1 << 3),
45244529
"reserve sufficient bits for serialized SIL");
4525-
static_assert(unsigned(SILAccessEnforcement::Last) < (1 << 2),
4530+
static_assert(unsigned(SILAccessEnforcement::Last) < (1 << 3),
45264531
"reserve sufficient bits for serialized SIL");
45274532

45284533
static_assert(unsigned(SILAccessKind::Last) <

include/swift/SIL/SILNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class alignas(8) SILNode :
122122
enum { NumAssignOwnershipQualifierBits = 2 };
123123
enum { NumAssignByWrapperModeBits = 2 };
124124
enum { NumSILAccessKindBits = 2 };
125-
enum { NumSILAccessEnforcementBits = 2 };
125+
enum { NumSILAccessEnforcementBits = 3 };
126126
enum { NumAllocRefTailTypesBits = 4 };
127127

128128
protected:

lib/AST/Expr.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,19 +1918,7 @@ void AbstractClosureExpr::setParameterList(ParameterList *P) {
19181918
P->setDeclContextOfParamDecls(this);
19191919
}
19201920

1921-
bool AbstractClosureExpr::hasBody() const {
1922-
switch (getKind()) {
1923-
case ExprKind::Closure:
1924-
case ExprKind::AutoClosure:
1925-
return true;
1926-
default:
1927-
return false;
1928-
}
1929-
}
1930-
19311921
BraceStmt * AbstractClosureExpr::getBody() const {
1932-
if (!hasBody())
1933-
return nullptr;
19341922
if (const AutoClosureExpr *autocls = dyn_cast<AutoClosureExpr>(this))
19351923
return autocls->getBody();
19361924
if (const ClosureExpr *cls = dyn_cast<ClosureExpr>(this))

lib/AST/TypeWrapper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ bool VarDecl::isTypeWrapperLocalStorageForInitializer() const {
4444
}
4545
return false;
4646
}
47+
48+
clang::PointerAuthQualifier VarDecl::getPointerAuthQualifier() const {
49+
if (auto *clangDecl = getClangDecl()) {
50+
if (auto *valueDecl = dyn_cast<clang::ValueDecl>(clangDecl)) {
51+
return valueDecl->getType().getPointerAuth();
52+
}
53+
}
54+
return clang::PointerAuthQualifier();
55+
}

0 commit comments

Comments
 (0)