diff --git a/stdlib/public/core/EmbeddedRuntime.swift b/stdlib/public/core/EmbeddedRuntime.swift index c4a15ce0a0a34..1526eeb3b36ec 100644 --- a/stdlib/public/core/EmbeddedRuntime.swift +++ b/stdlib/public/core/EmbeddedRuntime.swift @@ -154,12 +154,18 @@ func swift_retain_n_(object: UnsafeMutablePointer, n: UInt32) -> Uns } @_silgen_name("swift_release") -public func swift_release(object: UnsafeMutablePointer?) { +public func swift_release(object: Builtin.RawPointer) { swift_release_n(object: object, n: 1) } @_silgen_name("swift_release_n") -public func swift_release_n(object: UnsafeMutablePointer?, n: UInt32) { +public func swift_release_n(object: Builtin.RawPointer, n: UInt32) { + if Int(Builtin.ptrtoint_Word(object)) == 0 { return } + let o = UnsafeMutablePointer(object) + swift_release_n_(object: o, n: n) +} + +public func swift_release_n_(object: UnsafeMutablePointer?, n: UInt32) { guard let object else { return } diff --git a/test/embedded/runtime-release.swift b/test/embedded/runtime-release.swift new file mode 100644 index 0000000000000..efeb32b875d8d --- /dev/null +++ b/test/embedded/runtime-release.swift @@ -0,0 +1,23 @@ +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -O -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -Osize -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: optimized_stdlib +// REQUIRES: VENDOR=apple +// REQUIRES: OS=macosx + +@main +struct Main { + static func main() { + test() + print("Okay!") + // CHECK: Okay! + } +} + +func test() -> [Int] { + var s: [Int] = [] + s += [] + return s +}