Skip to content

Commit adea06f

Browse files
authored
Merge pull request #12717 from compnerd/dealloc_box
IRGen: properly handle deallocation of a boxed type
2 parents 7981630 + bdc38c9 commit adea06f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ class FixedBoxTypeInfoBase : public BoxTypeInfo {
15411541
auto size = layout.emitSize(IGF.IGM);
15421542
auto alignMask = layout.emitAlignMask(IGF.IGM);
15431543

1544+
IGF.emitNativeSetDeallocating(box);
15441545
emitDeallocateHeapObject(IGF, box, size, alignMask);
15451546
}
15461547

test/IRGen/alloc_box.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -o - | %FileCheck %s
2+
3+
func f() -> Bool? { return nil }
4+
5+
({
6+
guard var b = f() else { return }
7+
let c = { b = true }
8+
_ = (b, c)
9+
})()
10+
11+
// CHECK-LABEL: @_T09alloc_boxyycfU_
12+
// CHECK: <label>:8:
13+
// CHECK: call void @swift_setDeallocating
14+
// CHECK: call void @swift_rt_swift_deallocObject
15+

0 commit comments

Comments
 (0)