File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,8 @@ class DeadFunctionAndGlobalElimination {
212
212
for (const SILInstruction &initInst : *global) {
213
213
if (auto *fRef = dyn_cast<FunctionRefInst>(&initInst))
214
214
ensureAlive (fRef ->getReferencedFunction ());
215
+ if (auto *gRef = dyn_cast<GlobalAddrInst>(&initInst))
216
+ ensureAlive (gRef ->getReferencedGlobal ());
215
217
}
216
218
}
217
219
Original file line number Diff line number Diff line change 1
1
// RUN: %target-swift-frontend %s -O -emit-sil | %FileCheck %s
2
2
// RUN: %target-swift-frontend %s -O -emit-sil -enable-testing | %FileCheck -check-prefix=CHECK-TESTING %s
3
3
4
+ // Check if a private global is kept alive if it's only reference from another global variable.
5
+
6
+ private var g1 = 27
7
+ let g2 = UnsafePointer ( & g1)
8
+
4
9
// Check if cycles are removed.
5
10
6
11
@inline ( never)
@@ -184,6 +189,8 @@ public func keepPtrAlive() {
184
189
GFStr . aliveFuncPtr ( )
185
190
}
186
191
192
+ // CHECK-LABEL: sil_global private @$s25dead_function_elimination2g1{{.*}}
193
+
187
194
// CHECK-NOT: sil {{.*}}inCycleA
188
195
// CHECK-NOT: sil {{.*}}inCycleB
189
196
// CHECK-NOT: sil {{.*}}DeadMethod
Original file line number Diff line number Diff line change @@ -25,6 +25,30 @@ sil_global @globalFunctionPointer : $@callee_guaranteed () -> () = {
25
25
%initval = thin_to_thick_function %0 : $@convention(thin) () -> () to $@callee_guaranteed () -> ()
26
26
}
27
27
28
+ // CHECK-LABEL: sil_global private @self_referencing_private_global
29
+ sil_global private @self_referencing_private_global : $Builtin.RawPointer = {
30
+ %0 = global_addr @self_referencing_private_global : $*Builtin.RawPointer
31
+ %initval = address_to_pointer %0 : $*Builtin.RawPointer to $Builtin.RawPointer
32
+ }
33
+
34
+ // CHECK-LABEL: sil_global private @referencing_other_private_global
35
+ sil_global private @referencing_other_private_global : $Builtin.RawPointer = {
36
+ %0 = global_addr @self_referencing_private_global : $*Builtin.RawPointer
37
+ %initval = address_to_pointer %0 : $*Builtin.RawPointer to $Builtin.RawPointer
38
+ }
39
+
40
+ // CHECK-LABEL: sil_global @referencing_private_globals
41
+ sil_global @referencing_private_globals : $Builtin.RawPointer = {
42
+ %0 = global_addr @referencing_other_private_global : $*Builtin.RawPointer
43
+ %initval = address_to_pointer %0 : $*Builtin.RawPointer to $Builtin.RawPointer
44
+ }
45
+
46
+ // KEEP-NOT: @dead_self_referencing_private_global
47
+ sil_global private @dead_self_referencing_private_global : $Builtin.RawPointer = {
48
+ %0 = global_addr @dead_self_referencing_private_global : $*Builtin.RawPointer
49
+ %initval = address_to_pointer %0 : $*Builtin.RawPointer to $Builtin.RawPointer
50
+ }
51
+
28
52
// CHECK-LABEL: sil private @alivePrivateFunc
29
53
sil private @alivePrivateFunc : $@convention(thin) () -> () {
30
54
bb0:
You can’t perform that action at this time.
0 commit comments