Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SILOptimizer/Mandatory/AddressLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3365,6 +3365,11 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
yield->setOperand(use->getOperandNumber(), addr);
}

void visitIgnoredUseInst(IgnoredUseInst *ignored) {
SILValue addr = addrMat.materializeAddress(use->get());
ignored->setOperand(addr);
}

void visitValueMetatypeInst(ValueMetatypeInst *vmi) {
SILValue opAddr = addrMat.materializeAddress(use->get());
vmi->setOperand(opAddr);
Expand Down
28 changes: 28 additions & 0 deletions test/SILOptimizer/address_lowering.sil
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ sil [ossa] @takeGuaranteedObject : $@convention(thin) (@guaranteed AnyObject) ->
sil [ossa] @takeIndirectClass : $@convention(thin) (@in_guaranteed C) -> ()
sil [ossa] @takeTuple : $@convention(thin) <τ_0_0> (@in_guaranteed (τ_0_0, C)) -> ()

sil [ossa] @eraseToAny : $@convention(thin) <T> (@in_guaranteed T) -> @out Any
sil [ossa] @produceInt : $@convention(thin) () -> Int

sil [ossa] @takeIn : $@convention(thin) <T> (@in T) -> ()
sil [ossa] @takeInGuaranteed : $@convention(thin) <T> (@in_guaranteed T) -> ()
Expand Down Expand Up @@ -2555,6 +2557,32 @@ bb0:
return %retval : $()
}

// Verify that ignored_use of an address-only type gets lowered correctly.
// CHECK-LABEL: sil [ossa] @test_ignored_use : $@convention(thin) () -> () {
// CHECK: [[RETVAL_ADDR:%[^,]+]] = alloc_stack $Any
// CHECK: [[MAKE_INT:%[^,]+]] = function_ref @produceInt : $@convention(thin) () -> Builtin.Int64
// CHECK: [[INT:%[^,]+]] = apply [[MAKE_INT]]()
// CHECK: [[ERASE_FN:%[^,]+]] = function_ref @eraseToAny : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
// CHECK: [[ARG_ADDR:%[^,]+]] = alloc_stack $Builtin.Int64
// CHECK: store [[INT]] to [trivial] [[ARG_ADDR]] : $*Builtin.Int64
// CHECK: = apply [[ERASE_FN]]<Builtin.Int64>([[RETVAL_ADDR]], [[ARG_ADDR]]) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
// CHECK: dealloc_stack [[ARG_ADDR]] : $*Builtin.Int64
// CHECK: ignored_use [[RETVAL_ADDR]] : $*Any
// CHECK: destroy_addr [[RETVAL_ADDR]] : $*Any
// CHECK: dealloc_stack [[RETVAL_ADDR]] : $*Any
// CHECK: } // end sil function 'test_ignored_use'
sil [ossa] @test_ignored_use : $@convention(thin) () -> () {
bb0:
%1 = function_ref @produceInt : $@convention(thin) () -> Int
%2 = apply %1() : $@convention(thin) () -> Int
%3 = function_ref @eraseToAny : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
%4 = apply %3<Int>(%2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
ignored_use %4
destroy_value %4
%5 = tuple ()
return %5
}

// CHECK-LABEL: sil [ossa] @test_mark_unresolved_non_copyable_value_1_consumable_and_assignable : {{.*}} {
// CHECK: bb0([[T:%[^,]+]] :
// CHECK: [[TP:%[^,]+]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[T]]
Expand Down