Skip to content

Commit a2c4c57

Browse files
authored
Merge pull request #65796 from eeckstein/fix-dead-func-elimination
DeadFunctionElimination: an `alloc_global` instruction keeps the referenced global alive
2 parents d37b6bc + f381e42 commit a2c4c57

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ class DeadFunctionAndGlobalElimination {
362362
ensureKeyPathComponentIsAlive(component);
363363
} else if (auto *GA = dyn_cast<GlobalAddrInst>(&I)) {
364364
ensureAlive(GA->getReferencedGlobal());
365+
} else if (auto *agi = dyn_cast<AllocGlobalInst>(&I)) {
366+
ensureAlive(agi->getReferencedGlobal());
365367
} else if (auto *GV = dyn_cast<GlobalValueInst>(&I)) {
366368
ensureAlive(GV->getReferencedGlobal());
367369
} else if (auto *HSI = dyn_cast<HasSymbolInst>(&I)) {

test/SILOptimizer/remove_unused_func.sil

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ sil_stage canonical
66
import Builtin
77
import Swift
88

9+
// CHECK-LABEL: sil_global private @privateGlobal
10+
sil_global private @privateGlobal : $Int64
11+
912
// This function needs to be removed.
1013
// KEEP-NOT: @remove_me
1114

@@ -25,6 +28,7 @@ sil_global @globalFunctionPointer : $@callee_guaranteed () -> () = {
2528
// CHECK-LABEL: sil private @alivePrivateFunc
2629
sil private @alivePrivateFunc : $@convention(thin) () -> () {
2730
bb0:
31+
alloc_global @privateGlobal
2832
%0 = tuple ()
2933
return %0 : $()
3034
}

0 commit comments

Comments
 (0)