From 0a81f7fbecc20e4bab5ac3bd9ff0048415f60faf Mon Sep 17 00:00:00 2001 From: Kavon Farvardin Date: Tue, 30 Sep 2025 13:59:30 -0700 Subject: [PATCH] AddressLowering: handle ignored_use resolves rdar://158175192 --- .../Mandatory/AddressLowering.cpp | 5 ++++ test/SILOptimizer/address_lowering.sil | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/SILOptimizer/Mandatory/AddressLowering.cpp b/lib/SILOptimizer/Mandatory/AddressLowering.cpp index 189cd7bfbaac3..a25b63f46c55f 100644 --- a/lib/SILOptimizer/Mandatory/AddressLowering.cpp +++ b/lib/SILOptimizer/Mandatory/AddressLowering.cpp @@ -3365,6 +3365,11 @@ class UseRewriter : SILInstructionVisitor { 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); diff --git a/test/SILOptimizer/address_lowering.sil b/test/SILOptimizer/address_lowering.sil index d863ec0b932f6..b9f30c71cf475 100644 --- a/test/SILOptimizer/address_lowering.sil +++ b/test/SILOptimizer/address_lowering.sil @@ -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) (@in_guaranteed T) -> @out Any +sil [ossa] @produceInt : $@convention(thin) () -> Int sil [ossa] @takeIn : $@convention(thin) (@in T) -> () sil [ossa] @takeInGuaranteed : $@convention(thin) (@in_guaranteed T) -> () @@ -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]]([[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(%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]]