Skip to content

Commit 733dd86

Browse files
authored
Merge pull request #79896 from DougGregor/strict-memory-safety-cleanups
Strict memory safety cleanups
2 parents 24f4e64 + 7c8e99d commit 733dd86

File tree

13 files changed

+49
-37
lines changed

13 files changed

+49
-37
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3974,7 +3974,8 @@ bool CompilerInvocation::parseArgs(
39743974
"-Ounchecked");
39753975
}
39763976

3977-
if (!LangOpts.EnableAccessControl) {
3977+
if (!LangOpts.EnableAccessControl &&
3978+
FrontendOpts.ModuleName != SWIFT_ONONE_SUPPORT) {
39783979
Diags.diagnose(SourceLoc(),
39793980
diag::command_line_conflicts_with_strict_safety,
39803981
"-disable-access-control");

lib/Sema/DerivedConformanceDistributedActor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ deriveBodyDistributed_doInvokeOnReturn(AbstractFunctionDecl *afd, void *arg) {
156156
new (C) VarDecl(/*isStatic=*/false, VarDecl::Introducer::Let, sloc,
157157
C.getIdentifier("result"), afd);
158158
{
159-
auto resultLoadCall = CallExpr::createImplicit(
159+
Expr *resultLoadCall = CallExpr::createImplicit(
160160
C,
161161
UnresolvedDotExpr::createImplicit(
162162
C,
@@ -171,6 +171,9 @@ deriveBodyDistributed_doInvokeOnReturn(AbstractFunctionDecl *afd, void *arg) {
171171
new (C) DeclRefExpr(ConcreteDeclRef(returnTypeParam),
172172
dloc, implicit))}));
173173

174+
if (C.LangOpts.hasFeature(Feature::StrictMemorySafety))
175+
resultLoadCall = new (C) UnsafeExpr(sloc, resultLoadCall, Type(), true);
176+
174177
auto resultPattern = NamedPattern::createImplicit(C, resultVar);
175178
auto resultPB = PatternBindingDecl::createImplicit(
176179
C, swift::StaticSpellingKind::None, resultPattern,

stdlib/public/Concurrency/Task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,8 +1576,8 @@ internal func _getCurrentTaskName() -> UnsafePointer<UInt8>?
15761576

15771577
@available(SwiftStdlib 6.2, *)
15781578
internal func _getCurrentTaskNameString() -> String? {
1579-
if let stringPtr = _getCurrentTaskName() {
1580-
String(cString: stringPtr)
1579+
if let stringPtr = unsafe _getCurrentTaskName() {
1580+
unsafe String(cString: stringPtr)
15811581
} else {
15821582
nil
15831583
}

stdlib/public/Concurrency/TaskGroup+Embedded.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension TaskGroup {
3737
)
3838

3939
let builtinSerialExecutor =
40-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
40+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
4141

4242
_ = Builtin.createTask(
4343
flags: flags,
@@ -70,7 +70,7 @@ extension TaskGroup {
7070
)
7171

7272
let builtinSerialExecutor =
73-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
73+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
7474

7575
_ = Builtin.createTask(
7676
flags: flags,
@@ -103,7 +103,7 @@ extension ThrowingTaskGroup {
103103
)
104104

105105
let builtinSerialExecutor =
106-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
106+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
107107

108108
_ = Builtin.createTask(
109109
flags: flags,
@@ -136,7 +136,7 @@ extension ThrowingTaskGroup {
136136
)
137137

138138
let builtinSerialExecutor =
139-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
139+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
140140

141141
_ = Builtin.createTask(
142142
flags: flags,
@@ -169,7 +169,7 @@ extension DiscardingTaskGroup {
169169
)
170170

171171
let builtinSerialExecutor =
172-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
172+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
173173

174174
_ = Builtin.createTask(
175175
flags: flags,
@@ -202,7 +202,7 @@ extension DiscardingTaskGroup {
202202
)
203203

204204
let builtinSerialExecutor =
205-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
205+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
206206

207207
_ = Builtin.createTask(
208208
flags: flags,
@@ -235,7 +235,7 @@ extension ThrowingDiscardingTaskGroup {
235235
)
236236

237237
let builtinSerialExecutor =
238-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
238+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
239239

240240
_ = Builtin.createTask(
241241
flags: flags,
@@ -268,7 +268,7 @@ extension ThrowingDiscardingTaskGroup {
268268
)
269269

270270
let builtinSerialExecutor =
271-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
271+
unsafe Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
272272

273273
_ = Builtin.createTask(
274274
flags: flags,

stdlib/public/Cxx/CxxSpan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extension Span {
9595
_unsafeCxxSpan span: borrowing T,
9696
) {
9797
let buffer = unsafe UnsafeBufferPointer(start: span.__dataUnsafe(), count: Int(span.size()))
98-
let newSpan = Span(_unsafeElements: buffer)
98+
let newSpan = unsafe Span(_unsafeElements: buffer)
9999
// 'self' is limited to the caller's scope of the variable passed to the 'span' argument.
100100
self = unsafe _overrideLifetime(newSpan, borrowing: span)
101101
}

stdlib/public/Synchronization/Atomics/AtomicPointers.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension UnsafePointer: @unsafe AtomicRepresentable where Pointee: ~Copyable {
3737
public static func encodeAtomicRepresentation(
3838
_ value: consuming UnsafePointer<Pointee>
3939
) -> AtomicRepresentation {
40-
unsafe Int.encodeAtomicRepresentation(
40+
Int.encodeAtomicRepresentation(
4141
Int(bitPattern: value)
4242
)
4343
}
@@ -88,7 +88,7 @@ extension UnsafePointer: @unsafe AtomicOptionalRepresentable where Pointee: ~Cop
8888
public static func encodeAtomicOptionalRepresentation(
8989
_ value: consuming UnsafePointer<Pointee>?
9090
) -> AtomicOptionalRepresentation {
91-
unsafe Int.encodeAtomicRepresentation(
91+
Int.encodeAtomicRepresentation(
9292
Int(bitPattern: value)
9393
)
9494
}
@@ -143,7 +143,7 @@ extension UnsafeMutablePointer: @unsafe AtomicRepresentable where Pointee: ~Copy
143143
public static func encodeAtomicRepresentation(
144144
_ value: consuming UnsafeMutablePointer<Pointee>
145145
) -> AtomicRepresentation {
146-
unsafe Int.encodeAtomicRepresentation(
146+
Int.encodeAtomicRepresentation(
147147
Int(bitPattern: value)
148148
)
149149
}
@@ -195,7 +195,7 @@ where Pointee: ~Copyable {
195195
public static func encodeAtomicOptionalRepresentation(
196196
_ value: consuming UnsafeMutablePointer<Pointee>?
197197
) -> AtomicOptionalRepresentation {
198-
unsafe Int.encodeAtomicRepresentation(
198+
Int.encodeAtomicRepresentation(
199199
Int(bitPattern: value)
200200
)
201201
}
@@ -250,7 +250,7 @@ extension UnsafeRawPointer: @unsafe AtomicRepresentable {
250250
public static func encodeAtomicRepresentation(
251251
_ value: consuming UnsafeRawPointer
252252
) -> AtomicRepresentation {
253-
unsafe Int.encodeAtomicRepresentation(
253+
Int.encodeAtomicRepresentation(
254254
Int(bitPattern: value)
255255
)
256256
}
@@ -301,7 +301,7 @@ extension UnsafeRawPointer: @unsafe AtomicOptionalRepresentable {
301301
public static func encodeAtomicOptionalRepresentation(
302302
_ value: consuming UnsafeRawPointer?
303303
) -> AtomicOptionalRepresentation {
304-
unsafe Int.encodeAtomicRepresentation(
304+
Int.encodeAtomicRepresentation(
305305
Int(bitPattern: value)
306306
)
307307
}
@@ -356,7 +356,7 @@ extension UnsafeMutableRawPointer: @unsafe AtomicRepresentable {
356356
public static func encodeAtomicRepresentation(
357357
_ value: consuming UnsafeMutableRawPointer
358358
) -> AtomicRepresentation {
359-
unsafe Int.encodeAtomicRepresentation(
359+
Int.encodeAtomicRepresentation(
360360
Int(bitPattern: value)
361361
)
362362
}
@@ -407,7 +407,7 @@ extension UnsafeMutableRawPointer: @unsafe AtomicOptionalRepresentable {
407407
public static func encodeAtomicOptionalRepresentation(
408408
_ value: consuming UnsafeMutableRawPointer?
409409
) -> AtomicOptionalRepresentation {
410-
unsafe Int.encodeAtomicRepresentation(
410+
Int.encodeAtomicRepresentation(
411411
Int(bitPattern: value)
412412
)
413413
}
@@ -798,7 +798,7 @@ extension UnsafeBufferPointer: @unsafe AtomicRepresentable where Element: ~Copya
798798
) -> AtomicRepresentation {
799799
let valueCopy = unsafe value
800800

801-
return unsafe WordPair.encodeAtomicRepresentation(
801+
return WordPair.encodeAtomicRepresentation(
802802
WordPair(
803803
first: UInt(bitPattern: valueCopy.baseAddress),
804804
second: UInt(truncatingIfNeeded: valueCopy.count)
@@ -866,7 +866,7 @@ where Element: ~Copyable
866866
) -> AtomicRepresentation {
867867
let valueCopy = unsafe value
868868

869-
return unsafe WordPair.encodeAtomicRepresentation(
869+
return WordPair.encodeAtomicRepresentation(
870870
WordPair(
871871
first: UInt(bitPattern: valueCopy.baseAddress),
872872
second: UInt(truncatingIfNeeded: valueCopy.count)
@@ -932,7 +932,7 @@ extension UnsafeRawBufferPointer: @unsafe AtomicRepresentable {
932932
) -> AtomicRepresentation {
933933
let valueCopy = unsafe value
934934

935-
return unsafe WordPair.encodeAtomicRepresentation(
935+
return WordPair.encodeAtomicRepresentation(
936936
WordPair(
937937
first: UInt(bitPattern: valueCopy.baseAddress),
938938
second: UInt(truncatingIfNeeded: valueCopy.count)
@@ -998,7 +998,7 @@ extension UnsafeMutableRawBufferPointer: @unsafe AtomicRepresentable {
998998
) -> AtomicRepresentation {
999999
let valueCopy = unsafe value
10001000

1001-
return unsafe WordPair.encodeAtomicRepresentation(
1001+
return WordPair.encodeAtomicRepresentation(
10021002
WordPair(
10031003
first: UInt(bitPattern: valueCopy.baseAddress),
10041004
second: UInt(truncatingIfNeeded: valueCopy.count)

stdlib/public/core/AssertCommon.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal func _assertionFailure(
163163
if _isDebugAssertConfiguration() {
164164
var message = message
165165
message.withUTF8 { (messageUTF8) -> Void in
166-
_embeddedReportFatalErrorInFile(prefix: prefix, message: messageUTF8, file: file, line: line)
166+
unsafe _embeddedReportFatalErrorInFile(prefix: prefix, message: messageUTF8, file: file, line: line)
167167
}
168168
}
169169
#endif

stdlib/public/core/EmbeddedPrint.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func print(_ buf: UnsafeBufferPointer<UInt8>, terminator: StaticString = "\n") {
6767
for c in buf {
6868
putchar(CInt(c))
6969
}
70-
var p = terminator.utf8Start
71-
while p.pointee != 0 {
72-
putchar(CInt(p.pointee))
70+
var p = unsafe terminator.utf8Start
71+
while unsafe p.pointee != 0 {
72+
unsafe putchar(CInt(p.pointee))
7373
p += 1
7474
}
7575
}

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,5 +551,5 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
551551
print(line, terminator: ": ")
552552
print(prefix, terminator: "")
553553
if message.count > 0 { print(": ", terminator: "") }
554-
print(message)
554+
unsafe print(message)
555555
}

stdlib/public/core/PtrAuth.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ internal enum _PtrAuth {
9090
static func blend(pointer: UnsafeRawPointer,
9191
discriminator: UInt64) -> UInt64 {
9292
return UInt64(Builtin.int_ptrauth_blend(
93-
UInt64(unsafe UInt(bitPattern: pointer))._value,
93+
UInt64(UInt(bitPattern: pointer))._value,
9494
discriminator._value))
9595
}
9696

@@ -101,7 +101,7 @@ internal enum _PtrAuth {
101101
key: Key,
102102
discriminator: UInt64) -> UnsafeRawPointer {
103103
let bitPattern = UInt64(Builtin.int_ptrauth_sign(
104-
UInt64(unsafe UInt(bitPattern: pointer))._value,
104+
UInt64(UInt(bitPattern: pointer))._value,
105105
key._value._value,
106106
discriminator._value))
107107

@@ -118,7 +118,7 @@ internal enum _PtrAuth {
118118
newKey: Key,
119119
newDiscriminator: UInt64) -> UnsafeRawPointer {
120120
let bitPattern = UInt64(Builtin.int_ptrauth_resign(
121-
UInt64(unsafe UInt(bitPattern: pointer))._value,
121+
UInt64(UInt(bitPattern: pointer))._value,
122122
oldKey._value._value,
123123
oldDiscriminator._value,
124124
newKey._value._value,

0 commit comments

Comments
 (0)