Skip to content

Commit b63365c

Browse files
authored
Merge pull request #77858 from eeckstein/fix-deinit-devirtualizer
Devirtualization: make sure to de-serialize the body of shared deinit functions
2 parents 6010cfb + e156da9 commit b63365c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-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

include/swift/SIL/SILFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,9 @@ class SILFunction
10951095

10961096
/// Get the source location of the function.
10971097
SILLocation getLocation() const {
1098-
assert(DebugScope && "no scope/location");
1098+
if (!DebugScope) {
1099+
return SILLocation::invalid();
1100+
}
10991101
return getDebugScope()->Loc;
11001102
}
11011103

0 commit comments

Comments
 (0)