Skip to content

Commit c8cbf06

Browse files
committed
[embedded] Add a more targeted retain/release-in-deinit test
1 parent 249f7e6 commit c8cbf06

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/embedded/deinit-release2.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -O -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: OS=macosx || OS=linux-gnu
9+
10+
public var global_c: C? = nil
11+
12+
@inline(never) func opaque() { print(global_c == nil ? "global is nil" : "global is not nil") }
13+
14+
public class C {
15+
init() { print("init") }
16+
deinit {
17+
print("deinit")
18+
global_c = self
19+
opaque()
20+
global_c = nil
21+
opaque()
22+
print("end of deinit")
23+
}
24+
}
25+
26+
var bar: C? = C()
27+
bar = nil
28+
print("OK!")
29+
30+
// CHECK: init
31+
// CHECK: deinit
32+
// CHECK: global is not nil
33+
// CHECK: global is nil
34+
// CHECK: end of deinit
35+
// CHECK: OK!

0 commit comments

Comments
 (0)