Skip to content

Commit f668fea

Browse files
committed
[Standard library] Additional strict-memory-safety annotations
1 parent 29b4f3d commit f668fea

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

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,

stdlib/public/core/Span/RawSpan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ extension RawSpan {
440440
public func _extracting(
441441
unchecked bounds: ClosedRange<Int>
442442
) -> Self {
443-
let range = Range(
443+
let range = unsafe Range(
444444
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound + 1)
445445
)
446446
return unsafe _extracting(unchecked: range)

stdlib/public/core/Span/Span.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ extension Span where Element: ~Copyable {
590590
public func _extracting(
591591
unchecked bounds: ClosedRange<Index>
592592
) -> Self {
593-
let range = Range(
593+
let range = unsafe Range(
594594
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound + 1)
595595
)
596596
return unsafe _extracting(unchecked: range)

stdlib/public/core/VarArgs.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,12 @@ extension Float80: CVarArg, _CVarArgAligned {
447447
// runtime.
448448
@_fixed_layout
449449
@usableFromInline // c-abi
450+
@unsafe
450451
final internal class __VaListBuilder {
451452
#if arch(x86_64) || arch(s390x)
452453
@frozen // c-abi
453454
@usableFromInline
455+
@safe
454456
internal struct Header {
455457
@usableFromInline // c-abi
456458
internal var gp_offset = CUnsignedInt(0)
@@ -468,21 +470,27 @@ final internal class __VaListBuilder {
468470
#endif
469471

470472
@usableFromInline // c-abi
473+
@safe
471474
internal var gpRegistersUsed = 0
475+
472476
@usableFromInline // c-abi
477+
@safe
473478
internal var fpRegistersUsed = 0
474479

475480
#if arch(x86_64) || arch(s390x)
476481
@usableFromInline // c-abi
482+
@safe
477483
final // Property must be final since it is used by Builtin.addressof.
478484
internal var header = Header()
479485
#endif
480486

481487
@usableFromInline // c-abi
488+
@safe
482489
internal var storage: ContiguousArray<Int>
483490

484491
#if !_runtime(_ObjC)
485492
@usableFromInline // c-abi
493+
@safe
486494
internal var retainer = [CVarArg]()
487495
#endif
488496

@@ -560,9 +568,9 @@ final internal class __VaListBuilder {
560568
internal func va_list() -> CVaListPointer {
561569
#if arch(x86_64) || arch(s390x)
562570
header.reg_save_area = storage._baseAddress
563-
header.overflow_arg_area
571+
unsafe header.overflow_arg_area
564572
= storage._baseAddress + _registerSaveWords
565-
return CVaListPointer(
573+
return unsafe CVaListPointer(
566574
_fromUnsafeMutablePointer: UnsafeMutableRawPointer(
567575
Builtin.addressof(&self.header)))
568576
#elseif arch(arm64)

0 commit comments

Comments
 (0)