Skip to content

Commit f3a808d

Browse files
authored
Merge pull request swiftlang#77917 from swiftlang/fix-deinit-devirtualizer-6.1
[6.1] Devirtualization: make sure to de-serialize the body of shared deinit functions.
2 parents a8b30b7 + 14ab265 commit f3a808d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ extension MutatingContext {
227227
}
228228
}
229229

230+
func loadFunction(function: Function, loadCalleesRecursively: Bool) -> Bool {
231+
if function.isDefinition {
232+
return true
233+
}
234+
_bridged.loadFunction(function.bridged, loadCalleesRecursively)
235+
return function.isDefinition
236+
}
237+
230238
private func notifyNewInstructions(from: Instruction, to: Instruction) {
231239
var inst = from
232240
while inst != to {
@@ -305,14 +313,6 @@ struct FunctionPassContext : MutatingContext {
305313
}
306314
}
307315

308-
func loadFunction(function: Function, loadCalleesRecursively: Bool) -> Bool {
309-
if function.isDefinition {
310-
return true
311-
}
312-
_bridged.loadFunction(function.bridged, loadCalleesRecursively)
313-
return function.isDefinition
314-
}
315-
316316
/// Looks up a function in the `Swift` module.
317317
/// The `name` is the source name of the function and not the mangled name.
318318
/// Returns nil if no such function or multiple matching functions are found.

SwiftCompilerSources/Sources/Optimizer/Utilities/Devirtualization.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ private func devirtualize(destroy: some DevirtualizableDestroy, _ context: some
4343
guard let deinitFunc = context.lookupDeinit(ofNominal: nominal) else {
4444
return false
4545
}
46+
if deinitFunc.linkage == .shared && !deinitFunc.isDefinition {
47+
// Make sure to not have an external shared function, which is illegal in SIL.
48+
_ = context.loadFunction(function: deinitFunc, loadCalleesRecursively: false)
49+
}
4650
destroy.createDeinitCall(to: deinitFunc, context)
4751
context.erase(instruction: destroy)
4852
return true

test/SILOptimizer/stdlib/Atomics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -O -emit-sil -disable-availability-checking %s | %IRGenFileCheck %s
1+
// RUN: %target-swift-frontend -enable-ossa-modules -O -emit-sil -disable-availability-checking %s | %IRGenFileCheck %s
22

33
// REQUIRES: synchronization
44

0 commit comments

Comments
 (0)