Skip to content

Commit 3de5d6a

Browse files
committed
SIL: add get+set for enforcement in BeginAccessInst
1 parent b6e9c4c commit 3de5d6a

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,12 +1629,39 @@ final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
16291629
public var accessKind: AccessKind {
16301630
AccessKind(rawValue: bridged.BeginAccessInst_getAccessKind())!
16311631
}
1632-
public func set(accessKind: BeginAccessInst.AccessKind, context: some MutatingContext) {
1632+
public func set(accessKind: AccessKind, context: some MutatingContext) {
16331633
context.notifyInstructionsChanged()
16341634
bridged.BeginAccess_setAccessKind(accessKind.rawValue)
16351635
context.notifyInstructionChanged(self)
16361636
}
16371637

1638+
// The raw values must match SILAccessEnforcement.
1639+
public enum Enforcement: Int {
1640+
/// The access's enforcement has not yet been determined.
1641+
case unknown = 0
1642+
1643+
/// The access is statically known to not conflict with other accesses.
1644+
case `static` = 1
1645+
1646+
/// The access is not statically known to not conflict with anything and must be dynamically checked.
1647+
case dynamic = 2
1648+
1649+
/// The access is not statically known to not conflict with anything but dynamic checking should
1650+
/// be suppressed, leaving it undefined behavior.
1651+
case unsafe = 3
1652+
1653+
/// Access to pointers that are signed via pointer authentication.
1654+
case signed = 4
1655+
}
1656+
public var enforcement: Enforcement {
1657+
Enforcement(rawValue: bridged.BeginAccessInst_getEnforcement())!
1658+
}
1659+
public func set(enforcement: Enforcement, context: some MutatingContext) {
1660+
context.notifyInstructionsChanged()
1661+
bridged.BeginAccess_setEnforcement(enforcement.rawValue)
1662+
context.notifyInstructionChanged(self)
1663+
}
1664+
16381665
public var isStatic: Bool { bridged.BeginAccessInst_isStatic() }
16391666
public var isUnsafe: Bool { bridged.BeginAccessInst_isUnsafe() }
16401667

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@ struct BridgedInstruction {
824824
BRIDGED_INLINE bool BeginAccessInst_isStatic() const;
825825
BRIDGED_INLINE bool BeginAccessInst_isUnsafe() const;
826826
BRIDGED_INLINE void BeginAccess_setAccessKind(SwiftInt accessKind) const;
827+
BRIDGED_INLINE SwiftInt BeginAccessInst_getEnforcement() const;
828+
BRIDGED_INLINE void BeginAccess_setEnforcement(SwiftInt accessKind) const;
827829
BRIDGED_INLINE bool CopyAddrInst_isTakeOfSrc() const;
828830
BRIDGED_INLINE bool CopyAddrInst_isInitializationOfDest() const;
829831
BRIDGED_INLINE void CopyAddrInst_setIsTakeOfSrc(bool isTakeOfSrc) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,14 @@ void BridgedInstruction::BeginAccess_setAccessKind(SwiftInt accessKind) const {
14941494
getAs<swift::BeginAccessInst>()->setAccessKind((swift::SILAccessKind)accessKind);
14951495
}
14961496

1497+
SwiftInt BridgedInstruction::BeginAccessInst_getEnforcement() const {
1498+
return (SwiftInt)getAs<swift::BeginAccessInst>()->getEnforcement();
1499+
}
1500+
1501+
void BridgedInstruction::BeginAccess_setEnforcement(SwiftInt accessKind) const {
1502+
getAs<swift::BeginAccessInst>()->setEnforcement((swift::SILAccessEnforcement)accessKind);
1503+
}
1504+
14971505
bool BridgedInstruction::CopyAddrInst_isTakeOfSrc() const {
14981506
return getAs<swift::CopyAddrInst>()->isTakeOfSrc();
14991507
}

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4885,6 +4885,7 @@ class EndBorrowInst
48854885
};
48864886

48874887
/// Different kinds of access.
4888+
/// This enum must stay in sync with `BeginAccessInst.AccessKind` in SwiftCompilerSources.
48884889
enum class SILAccessKind : uint8_t {
48894890
/// An access which takes uninitialized memory and initializes it.
48904891
Init,
@@ -4907,6 +4908,7 @@ enum { NumSILAccessKindBits = 2 };
49074908
StringRef getSILAccessKindName(SILAccessKind kind);
49084909

49094910
/// Different kinds of exclusivity enforcement for accesses.
4911+
/// This enum must stay in sync with `BeginAccessInst.Enforcement` in SwiftCompilerSources.
49104912
enum class SILAccessEnforcement : uint8_t {
49114913
/// The access's enforcement has not yet been determined.
49124914
Unknown,

0 commit comments

Comments
 (0)