Skip to content

Commit ee65ebb

Browse files
authored
Merge pull request #74474 from eeckstein/fix-deinit-devirt
Deinit-Devirtualization: fix a crash when trying to de-virtualize a non-copyable generic
2 parents 7c16527 + 715a765 commit ee65ebb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Devirtualization.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ private func devirtualize(destroy: some DevirtualizableDestroy, _ context: some
3333
if !type.isMoveOnly {
3434
return true
3535
}
36-
precondition(type.isNominal, "non-copyable non-nominal types not supported, yet")
36+
37+
if !type.isNominal {
38+
// E.g. a non-copyable generic function parameter
39+
return true
40+
}
3741

3842
let result: Bool
3943
if type.nominal.hasValueDeinit && !destroy.shouldDropDeinit {

test/SILOptimizer/devirt_deinits.sil

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ bb0(%0 : $*S4):
273273
return %r : $()
274274
}
275275

276+
// CHECK-LABEL: sil [ossa] @nonCopyable_generic :
277+
// CHECK: destroy_addr %0
278+
// CHECK: } // end sil function 'nonCopyable_generic'
279+
sil [ossa] @nonCopyable_generic : $@convention(thin) <T where T : ~Copyable> (@in T) -> () {
280+
bb0(%0 : $*T):
281+
destroy_addr %0 : $*T
282+
%r = tuple ()
283+
return %r : $()
284+
}
285+
276286
sil @s1_deinit : $@convention(method) (@owned S1) -> ()
277287
sil @s2_deinit : $@convention(method) (@owned S2) -> ()
278288
sil @s3_deinit : $@convention(method) <T> (@in S3<T>) -> ()

0 commit comments

Comments
 (0)