Skip to content

Commit d4c1a3a

Browse files
authored
Merge pull request #74477 from atrick/fix-moveonlytype
Fix MoveOnlyWrappedTypeEliminator; handle dealloc_box
2 parents 61421e8 + 2f747ad commit d4c1a3a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
180180
NO_UPDATE_NEEDED(MarkDependence)
181181
NO_UPDATE_NEEDED(DestroyAddr)
182182
NO_UPDATE_NEEDED(DeallocStack)
183+
NO_UPDATE_NEEDED(DeallocBox)
183184
NO_UPDATE_NEEDED(Branch)
184185
NO_UPDATE_NEEDED(ExplicitCopyAddr)
185186
NO_UPDATE_NEEDED(CopyAddr)

test/SILOptimizer/moveonly_type_eliminator.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,24 @@ bb0(%x : @owned $Klass):
578578
%retval = tuple ()
579579
return %retval : $()
580580
}
581+
582+
// SILGen occasionally uses dealloc_box instead of destroy_value. dealloc_box is needed when we don't want to destroy
583+
// the contents of the box. It seems to happen with property wrappers.
584+
//
585+
// CHECK-LABEL: sil [ossa] @dealoc_box : $@convention(thin) (@owned Klass) -> () {
586+
// CHECK: [[BOX:%.*]] = alloc_box [moveable_value_debuginfo] ${ var Klass }
587+
// CHECK: dealloc_box [[BOX]] : ${ var Klass }
588+
// CHECK-LABEL: } // end sil function 'dealoc_box'
589+
sil [ossa] @dealoc_box : $@convention(thin) (@owned Klass) -> () {
590+
bb0(%x : @owned $Klass):
591+
%box = alloc_box ${ var @moveOnly Klass }
592+
%addr = project_box %box : ${ var @moveOnly Klass }, 0
593+
%unwrapped_addr = moveonlywrapper_to_copyable_addr %addr : $*@moveOnly Klass
594+
store %x to [init] %unwrapped_addr : $*Klass
595+
debug_value %addr : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
596+
destroy_addr %addr : $*@moveOnly Klass
597+
debug_value undef : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
598+
dealloc_box %box : ${ var @moveOnly Klass }
599+
%retval = tuple ()
600+
return %retval : $()
601+
}

0 commit comments

Comments
 (0)