mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[embedded] Add swift_allocEmptyBox to the embedded runtime
This commit is contained in:
@@ -236,6 +236,15 @@ func swift_initStackObject(metadata: UnsafeMutablePointer<ClassMetadata>, object
|
|||||||
return unsafe 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
|
/// Refcounting
|
||||||
|
|||||||
24
test/embedded/empty-box.swift
Normal file
24
test/embedded/empty-box.swift
Normal 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!
|
||||||
Reference in New Issue
Block a user