[embedded] Add swift_allocEmptyBox to the embedded runtime

This commit is contained in:
Kuba Mracek
2025-04-21 15:47:34 -07:00
parent e9253b749f
commit c0ea02f86d
2 changed files with 33 additions and 0 deletions

View File

@@ -236,6 +236,15 @@ func swift_initStackObject(metadata: UnsafeMutablePointer<ClassMetadata>, object
return unsafe object
}
@unsafe
public var _emptyBoxStorage: (Int, Int) = (/*isa*/0, /*refcount*/-1)
@_cdecl("swift_allocEmptyBox")
public func swift_allocEmptyBox() -> Builtin.RawPointer {
let box = unsafe Builtin.addressof(&_emptyBoxStorage)
swift_retain(object: box)
return box
}
/// Refcounting

View File

@@ -0,0 +1,24 @@
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -wmo) | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: swift_feature_Embedded
public struct ZeroSizedStruct {}
var escape: (()->())? = nil
public func sink<T>(t: inout T) {
}
public func foo() {
var s = ZeroSizedStruct()
escape = {
sink(t: &s)
}
}
foo()
print("OK!")
// CHECK: OK!