Skip to content

Commit 7977e46

Browse files
committed
Add a ChangeLog entry for SE-0458
1 parent 939d4d7 commit 7977e46

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
> [!NOTE]
44
> This is in reverse chronological order, so newer entries are added to the top.
55
6+
## Swift 6.2
7+
8+
* [SE-0458][]:
9+
Introduced an opt-in mode for strict checking of memory safety, which can be
10+
enabled with the compiler flag `-strict-memory-safety`. In this mode,
11+
the Swift compiler will produce warnings for uses of memory-unsafe constructs
12+
and APIs. For example,
13+
14+
```swift
15+
func evilMalloc(size: Int) -> Int {
16+
// warning: call to global function 'malloc' involves unsafe type 'UnsafeMutableRawPointer'
17+
return Int(bitPattern: malloc(size))
18+
}
19+
```
20+
21+
These warnings are in their own diagnostic group (`Unsafe`) and can
22+
be suppressed by ackwnowledging the memory-unsafe behavior, for
23+
example with an `unsafe` expression:
24+
25+
```swift
26+
func evilMalloc(size: Int) -> Int {
27+
return unsafe Int(bitPattern: malloc(size)) // no warning
28+
}
29+
```
30+
631
## Swift 6.1
732

833
* Previous versions of Swift would incorrectly allow Objective-C `-init...`
@@ -10676,6 +10701,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
1067610701
[SE-0431]: https://github.com/apple/swift-evolution/blob/main/proposals/0431-isolated-any-functions.md
1067710702
[SE-0442]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0442-allow-taskgroup-childtaskresult-type-to-be-inferred.md
1067810703
[SE-0444]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
10704+
[SE-0458]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0458-strict-memory-safety.md
1067910705
[#64927]: <https://github.com/apple/swift/issues/64927>
1068010706
[#42697]: <https://github.com/apple/swift/issues/42697>
1068110707
[#42728]: <https://github.com/apple/swift/issues/42728>

userdocs/diagnostic_groups/Unsafe.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ This diagnostic group includes warnings that identify the use of unsafe language
2323
return Int(bitPattern: malloc(size))
2424
}
2525
```
26+
27+
These warnings can be suppressed using an `unsafe` expression, which acknowledges the presence of memory-unsafe code. For example:
28+
29+
```swift
30+
func evilMalloc(size: Int) -> Int {
31+
return unsafe Int(bitPattern: malloc(size))
32+
}
33+
```
34+
35+
The warnings produced by this diagnostic group can be enabled with the compiler
36+
flag `-strict-memory-safety`.

0 commit comments

Comments
 (0)