Skip to content

Commit 715a765

Browse files
committed
Deinit-Devirtualization: fix a crash when trying to de-virtualize a non-copyable generic
rdar://129980818
1 parent 7c16527 commit 715a765

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: SwiftCompilerSources/Sources/Optimizer/Utilities/Devirtualization.swift

+5-1
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 {

Diff for: test/SILOptimizer/devirt_deinits.sil

+10
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)