Skip to content

Commit 3ac9fc6

Browse files
committed
InitializeStaticGlobals: remove dead instructions in global initializer
After removing the store it's required to remove the remaining dead instructions to avoid ownership verifier errors. rdar://109999674
1 parent 92fab06 commit 3ac9fc6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/InitializeStaticGlobals.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ let initializeStaticGlobalsPass = FunctionPass(name: "initialize-static-globals"
6363

6464
context.erase(instruction: allocInst)
6565
context.erase(instruction: storeToGlobal)
66+
context.removeTriviallyDeadInstructionsIgnoringDebugUses(in: function)
6667
}
6768

6869
/// Analyses the global initializer function and returns the `alloc_global` and `store`

test/SILOptimizer/static_enums.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ func getStringGen(_ s: StringGen) -> String {
161161
}
162162
}
163163

164+
public enum R {
165+
case success(Int)
166+
case failure(Error)
167+
}
168+
169+
public let success: R = .success(27)
170+
171+
// CHECK-LABEL: sil_global hidden @$s4test10optSuccessAA1ROSgvp : $Optional<R> = {
172+
var optSuccess: R? = success
173+
164174
// CHECK-LABEL: sil_global private @$s4test9createArrSaySiSgGyFTv_ : $_ContiguousArrayStorage<Optional<Int>> = {
165175
@inline(never)
166176
func createArr() -> [Int?] {
@@ -234,6 +244,8 @@ struct Main {
234244
print("stringGen2: \(getStringGen(sg2))")
235245
// CHECK-OUTPUT: stringGen3: str
236246
print("stringGen3: \(getStringGen(sg3))")
247+
// CHECK-OUTPUT: optSuccess: Optional(test.R.success(27))
248+
print("optSuccess:", optSuccess as Any)
237249
}
238250
}
239251

0 commit comments

Comments
 (0)