Skip to content

Commit 7ee404a

Browse files
committed
[AddressLowering] Take from cast destination.
When lowering an unconditional_checked_cast from an address-only value to a loadable value, the value with which to replace the original is a load of the destination address of the unconditional_checked_cast_addr to which the instruction was lowered. In the case of non-trivial values, that load must be a take.
1 parent 1023583 commit 7ee404a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ void UseRewriter::visitUnconditionalCheckedCastInst(
32983298
uncondCheckedCast->getLoc(), destAddr,
32993299
destAddr->getType().isTrivial(*uncondCheckedCast->getFunction())
33003300
? LoadOwnershipQualifier::Trivial
3301-
: LoadOwnershipQualifier::Copy);
3301+
: LoadOwnershipQualifier::Take);
33023302
nextBuilder.createDeallocStack(uncondCheckedCast->getLoc(), destAddr);
33033303
uncondCheckedCast->replaceAllUsesWith(dest);
33043304
}

test/SILOptimizer/address_lowering.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,20 @@ entry(%instance : @owned $T):
20772077
return %retval : $()
20782078
}
20792079

2080+
// CHECK-LABEL: sil [ossa] @test_unconditional_checked_cast6 : {{.*}} {
2081+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
2082+
// CHECK: [[ADDR:%[^,]+]] = alloc_stack $Klass
2083+
// CHECK: unconditional_checked_cast_addr T in [[INSTANCE]]
2084+
// CHECK: [[KLASS:%[^,]+]] = load [take] [[ADDR]]
2085+
// CHECK: dealloc_stack [[ADDR]]
2086+
// CHECK-LABEL: } // end sil function 'test_unconditional_checked_cast6'
2087+
sil [ossa] @test_unconditional_checked_cast6 : $@convention(method) <T> (@in T) -> () {
2088+
bb0(%instance : @owned $T):
2089+
%klass = unconditional_checked_cast %instance : $T to Klass
2090+
destroy_value %klass : $Klass
2091+
%retval = tuple ()
2092+
return %retval : $()
2093+
}
20802094
// CHECK-LABEL: sil [ossa] @test_yield_1_two_values : {{.*}} {
20812095
// CHECK: tuple_element_addr
20822096
// CHECK: tuple_element_addr

0 commit comments

Comments
 (0)