Skip to content

Commit c256c1f

Browse files
authored
Merge pull request #72563 from kubamracek/embedded-isUniquelyReferenced_native
[embedded] Add swift_isUniquelyReferenced_native into the embedded runtime
2 parents 311c55f + 8f247e2 commit c256c1f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ func swift_initStackObject(metadata: UnsafeMutablePointer<ClassMetadata>, object
146146
public func swift_setDeallocating(object: Builtin.RawPointer) {
147147
}
148148

149+
@_cdecl("swift_isUniquelyReferenced_native")
150+
public func swift_isUniquelyReferenced_native(object: Builtin.RawPointer) -> Bool {
151+
if Int(Builtin.ptrtoint_Word(object)) == 0 { return false }
152+
return swift_isUniquelyReferenced_nonNull_native(object: UnsafeMutablePointer<HeapObject>(object))
153+
}
154+
149155
@_cdecl("swift_isUniquelyReferenced_nonNull_native")
150156
public func swift_isUniquelyReferenced_nonNull_native(object: Builtin.RawPointer) -> Bool {
151157
return swift_isUniquelyReferenced_nonNull_native(object: UnsafeMutablePointer<HeapObject>(object))

test/embedded/classes-optional.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -c -o %t/main.o
3+
// RUN: %target-clang %t/main.o -o %t/a.out -dead_strip
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: executable_test
8+
// REQUIRES: optimized_stdlib
9+
// REQUIRES: OS=macosx || OS=linux-gnu
10+
11+
class Foo {
12+
var foo: Foo?
13+
}
14+
15+
do {
16+
_ = Foo()
17+
print("OK!")
18+
}
19+
// CHECK: OK!

0 commit comments

Comments
 (0)