Commit a946922
committed
Fix SILCombine miscompile for discard on non-copyable types
Fixes rdar://113214179 (Raw layout types don't adhere to discard self)
// swift-frontend ./rawdeinit.swift -enable-experimental-feature RawLayout \
// -enable-builtin-module -emit-sil -o rawdeinit.sil
import Builtin
@_rawLayout(like: T)
public struct Cell<T>: ~Copyable {
var ptr: UnsafeMutablePointer<T> {
.init(Builtin.unprotectedAddressOfBorrow(self))
}
init(_ initialValue: T) {
ptr.initialize(to: initialValue)
}
deinit {
ptr.deinitialize(count: 1)
}
public consuming func get() -> T {
let value = ptr.move()
discard self // SILCombine inserts a destroy of self here
return value
}
}1 parent a7f9182 commit a946922
File tree
2 files changed
+35
-0
lines changed- lib/SILOptimizer/SILCombiner
- test/SILOptimizer
2 files changed
+35
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
374 | 386 | | |
375 | 387 | | |
376 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
0 commit comments