Skip to content

Commit 0a81f7f

Browse files
committed
AddressLowering: handle ignored_use
resolves rdar://158175192
1 parent cc8f060 commit 0a81f7f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,11 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
33653365
yield->setOperand(use->getOperandNumber(), addr);
33663366
}
33673367

3368+
void visitIgnoredUseInst(IgnoredUseInst *ignored) {
3369+
SILValue addr = addrMat.materializeAddress(use->get());
3370+
ignored->setOperand(addr);
3371+
}
3372+
33683373
void visitValueMetatypeInst(ValueMetatypeInst *vmi) {
33693374
SILValue opAddr = addrMat.materializeAddress(use->get());
33703375
vmi->setOperand(opAddr);

test/SILOptimizer/address_lowering.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ sil [ossa] @takeGuaranteedObject : $@convention(thin) (@guaranteed AnyObject) ->
107107
sil [ossa] @takeIndirectClass : $@convention(thin) (@in_guaranteed C) -> ()
108108
sil [ossa] @takeTuple : $@convention(thin) <τ_0_0> (@in_guaranteed (τ_0_0, C)) -> ()
109109

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

111113
sil [ossa] @takeIn : $@convention(thin) <T> (@in T) -> ()
112114
sil [ossa] @takeInGuaranteed : $@convention(thin) <T> (@in_guaranteed T) -> ()
@@ -2555,6 +2557,32 @@ bb0:
25552557
return %retval : $()
25562558
}
25572559

2560+
// Verify that ignored_use of an address-only type gets lowered correctly.
2561+
// CHECK-LABEL: sil [ossa] @test_ignored_use : $@convention(thin) () -> () {
2562+
// CHECK: [[RETVAL_ADDR:%[^,]+]] = alloc_stack $Any
2563+
// CHECK: [[MAKE_INT:%[^,]+]] = function_ref @produceInt : $@convention(thin) () -> Builtin.Int64
2564+
// CHECK: [[INT:%[^,]+]] = apply [[MAKE_INT]]()
2565+
// CHECK: [[ERASE_FN:%[^,]+]] = function_ref @eraseToAny : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
2566+
// CHECK: [[ARG_ADDR:%[^,]+]] = alloc_stack $Builtin.Int64
2567+
// CHECK: store [[INT]] to [trivial] [[ARG_ADDR]] : $*Builtin.Int64
2568+
// CHECK: = apply [[ERASE_FN]]<Builtin.Int64>([[RETVAL_ADDR]], [[ARG_ADDR]]) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
2569+
// CHECK: dealloc_stack [[ARG_ADDR]] : $*Builtin.Int64
2570+
// CHECK: ignored_use [[RETVAL_ADDR]] : $*Any
2571+
// CHECK: destroy_addr [[RETVAL_ADDR]] : $*Any
2572+
// CHECK: dealloc_stack [[RETVAL_ADDR]] : $*Any
2573+
// CHECK: } // end sil function 'test_ignored_use'
2574+
sil [ossa] @test_ignored_use : $@convention(thin) () -> () {
2575+
bb0:
2576+
%1 = function_ref @produceInt : $@convention(thin) () -> Int
2577+
%2 = apply %1() : $@convention(thin) () -> Int
2578+
%3 = function_ref @eraseToAny : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
2579+
%4 = apply %3<Int>(%2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @out Any
2580+
ignored_use %4
2581+
destroy_value %4
2582+
%5 = tuple ()
2583+
return %5
2584+
}
2585+
25582586
// CHECK-LABEL: sil [ossa] @test_mark_unresolved_non_copyable_value_1_consumable_and_assignable : {{.*}} {
25592587
// CHECK: bb0([[T:%[^,]+]] :
25602588
// CHECK: [[TP:%[^,]+]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[T]]

0 commit comments

Comments
 (0)