Skip to content

Commit 1616c29

Browse files
committed
[AddressLowering] Reserve capacity, don't resize.
Resizing a SmallVector of SILValues fills it with invalid SILValues. THe intent is to reserve space for forthcoming values.
1 parent c2805e5 commit 1616c29

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ void OpaqueStorageAllocation::allocatePhi(PhiValue phi) {
11591159
coalescedPhi.coalesce(phi, pass.valueStorageMap);
11601160

11611161
SmallVector<SILValue, 4> coalescedValues;
1162-
coalescedValues.resize(coalescedPhi.getCoalescedOperands().size());
1162+
coalescedValues.reserve(coalescedPhi.getCoalescedOperands().size());
11631163
for (SILValue value : coalescedPhi.getCoalescedValues())
11641164
coalescedValues.push_back(value);
11651165

test/SILOptimizer/address_lowering_phi.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,20 @@ merge(%34 : @owned $Value):
500500
%43 = tuple ()
501501
return %43 : $()
502502
}
503+
504+
// CHECK-LABEL: sil [ossa] @f105_phi_into_tuple : {{.*}} {
505+
// CHECK: [[STORAGE:%[^,]+]] = alloc_stack $(Self, Builtin.Int1)
506+
// CHECK: [[SELF_ADDR:%[^,]+]] = tuple_element_addr [[STORAGE]]
507+
// CHECK: apply {{%[^,]+}}<Self>([[SELF_ADDR]])
508+
// CHECK-LABEL: } // end sil function 'f105_phi_into_tuple'
509+
sil [ossa] @f105_phi_into_tuple : $@convention(thin) <Self> () -> () {
510+
%getOut = function_ref @getOut : $@convention(thin) <T> () -> @out T
511+
%self = apply %getOut<Self>() : $@convention(thin) <τ_0_0> () -> @out τ_0_0
512+
br exit(%self : $Self)
513+
514+
exit(%self_2 : @owned $Self):
515+
%tuple = tuple (%self_2 : $Self, undef : $Bool)
516+
destroy_value %tuple : $(Self, Bool)
517+
%retval = tuple ()
518+
return %retval : $()
519+
}

0 commit comments

Comments
 (0)