mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety as we expected to warn at the use of the returned value: let x = returnsUnsafe() usesUnsafe(x) // warn here Unfortunately, this resulted in missing some unsafe constructs that can introduce memory safety issues when the use of the return value had a different shape resulting in false negatives for cases like: return returnsUnsafe() or usesUnsafe(returnsUnsafe()) This PR changes the analysis to always take return types of function calls into account. rdar://157237301
This commit is contained in:
@@ -157,7 +157,7 @@ public func swift_slowAlloc(_ size: Int, _ alignMask: Int) -> UnsafeMutableRawPo
|
||||
} else {
|
||||
alignment = alignMask + 1
|
||||
}
|
||||
return alignedAlloc(size: size, alignment: alignment)
|
||||
return unsafe alignedAlloc(size: size, alignment: alignment)
|
||||
}
|
||||
|
||||
@_cdecl("swift_slowDealloc")
|
||||
@@ -171,7 +171,7 @@ public func swift_allocObject(metadata: Builtin.RawPointer, requiredSize: Int, r
|
||||
}
|
||||
|
||||
func swift_allocObject(metadata: UnsafeMutablePointer<ClassMetadata>, requiredSize: Int, requiredAlignmentMask: Int) -> UnsafeMutablePointer<HeapObject> {
|
||||
let p = swift_slowAlloc(requiredSize, requiredAlignmentMask)!
|
||||
let p = unsafe swift_slowAlloc(requiredSize, requiredAlignmentMask)!
|
||||
let object = unsafe p.assumingMemoryBound(to: HeapObject.self)
|
||||
unsafe _swift_embedded_set_heap_object_metadata_pointer(object, metadata)
|
||||
unsafe object.pointee.refcount = 1
|
||||
|
||||
Reference in New Issue
Block a user