[6.2][StrictMemorySafety] Check the safety of return types of calls

Explanation: There were some scenarios where we could call an unsafe
function without marking the expression as unsafe. These affect mostly
cases where the function's result is passed to another function or
returned. This PR makes sure we always flag functions with unsafe return
types, even if their result is not stored anywhere for later use.
Issues: rdar://157237301
Original PRs: #83520
Risk: Low, worst case scenario the user has to add redundant unsafe
keywords in strict memory safe mode.
Testing: Added a compiler test.
Reviewers: @DougGregor
This commit is contained in:
Gábor Horváth
2025-08-08 06:39:39 +01:00
committed by Gabor Horvath
parent fe4880072e
commit 99f9c318ca
40 changed files with 126 additions and 98 deletions

View File

@@ -73,7 +73,7 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
}
// Look for contiguous storage in the NSArray
let cocoaStorageBaseAddress = self.contiguousStorage(self.indices)
let cocoaStorageBaseAddress = unsafe self.contiguousStorage(self.indices)
if let cocoaStorageBaseAddress = unsafe cocoaStorageBaseAddress {
return unsafe _SliceBuffer(
@@ -113,7 +113,7 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
) -> UnsafeMutablePointer<AnyObject>?
{
_internalInvariant(!subRange.isEmpty)
var enumerationState = _makeSwiftNSFastEnumerationState()
var enumerationState = unsafe _makeSwiftNSFastEnumerationState()
// This function currently returns nil unless the first
// subRange.upperBound items are stored contiguously. This is an