Skip to content

Commit ba052ab

Browse files
committed
Add signed access enforcement to begin_access
This will be used for supporting imported c function pointers with custom __ptrauth qualifier.
1 parent 9239a40 commit ba052ab

File tree

8 files changed

+23
-4
lines changed

8 files changed

+23
-4
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/SIL/SILInstruction.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,8 +4418,13 @@ enum class SILAccessEnforcement : uint8_t {
44184418
/// behavior.
44194419
Unsafe,
44204420

4421+
/// Access to pointers that are signed via pointer authentication mechanishm.
4422+
/// Such pointers should be authenticated before read and signed before a
4423+
/// write. Optimizer should avoid promoting such accesses to values.
4424+
Signed,
4425+
44214426
// This enum is encoded.
4422-
Last = Unsafe
4427+
Last = Signed
44234428
};
44244429
StringRef getSILAccessEnforcementName(SILAccessEnforcement enforcement);
44254430

@@ -4492,9 +4497,9 @@ class BeginAccessInst
44924497
: BeginAccessBase(loc, accessKind, enforcement, noNestedConflict,
44934498
fromBuiltin, lvalue, lvalue->getType()) {
44944499

4495-
static_assert(unsigned(SILAccessKind::Last) < (1 << 2),
4500+
static_assert(unsigned(SILAccessKind::Last) < (1 << 3),
44964501
"reserve sufficient bits for serialized SIL");
4497-
static_assert(unsigned(SILAccessEnforcement::Last) < (1 << 2),
4502+
static_assert(unsigned(SILAccessEnforcement::Last) < (1 << 3),
44984503
"reserve sufficient bits for serialized SIL");
44994504

45004505
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/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5750,6 +5750,7 @@ void IRGenSILFunction::visitBeginAccessInst(BeginAccessInst *access) {
57505750

57515751
case SILAccessEnforcement::Static:
57525752
case SILAccessEnforcement::Unsafe:
5753+
case SILAccessEnforcement::Signed:
57535754
// nothing to do
57545755
setLoweredAddress(access, addr);
57555756
return;
@@ -5790,6 +5791,7 @@ void IRGenSILFunction::visitBeginUnpairedAccessInst(
57905791

57915792
case SILAccessEnforcement::Static:
57925793
case SILAccessEnforcement::Unsafe:
5794+
case SILAccessEnforcement::Signed:
57935795
// nothing to do
57945796
return;
57955797

@@ -5835,6 +5837,7 @@ void IRGenSILFunction::visitEndAccessInst(EndAccessInst *i) {
58355837

58365838
case SILAccessEnforcement::Static:
58375839
case SILAccessEnforcement::Unsafe:
5840+
case SILAccessEnforcement::Signed:
58385841
// nothing to do
58395842
return;
58405843

@@ -5862,6 +5865,7 @@ void IRGenSILFunction::visitEndUnpairedAccessInst(EndUnpairedAccessInst *i) {
58625865

58635866
case SILAccessEnforcement::Static:
58645867
case SILAccessEnforcement::Unsafe:
5868+
case SILAccessEnforcement::Signed:
58655869
// nothing to do
58665870
return;
58675871

lib/SIL/IR/SILInstructions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,8 @@ StringRef swift::getSILAccessEnforcementName(SILAccessEnforcement enforcement) {
12061206
case SILAccessEnforcement::Static: return "static";
12071207
case SILAccessEnforcement::Dynamic: return "dynamic";
12081208
case SILAccessEnforcement::Unsafe: return "unsafe";
1209+
case SILAccessEnforcement::Signed:
1210+
return "signed";
12091211
}
12101212
llvm_unreachable("bad access enforcement");
12111213
}

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,6 +4326,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
43264326
setEnforcement(SILAccessEnforcement::Dynamic);
43274327
} else if (attr == "unsafe") {
43284328
setEnforcement(SILAccessEnforcement::Unsafe);
4329+
} else if (attr == "signed") {
4330+
setEnforcement(SILAccessEnforcement::Signed);
43294331
} else if (attr == "init") {
43304332
setKind(SILAccessKind::Init);
43314333
} else if (attr == "read") {

lib/SILOptimizer/Mandatory/AccessMarkerElimination.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ bool AccessMarkerElimination::shouldPreserveAccess(
7777
switch (enforcement) {
7878
case SILAccessEnforcement::Static:
7979
case SILAccessEnforcement::Unsafe:
80+
case SILAccessEnforcement::Signed:
8081
return false;
8182
case SILAccessEnforcement::Unknown:
8283
case SILAccessEnforcement::Dynamic:

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ static InlineCost getEnforcementCost(SILAccessEnforcement enforcement) {
770770
return InlineCost::Expensive;
771771
case SILAccessEnforcement::Static:
772772
case SILAccessEnforcement::Unsafe:
773+
case SILAccessEnforcement::Signed:
773774
return InlineCost::Free;
774775
}
775776
llvm_unreachable("bad enforcement");

0 commit comments

Comments
 (0)