Skip to content

Commit 81d37be

Browse files
committed
[AddressLowering] Fix dead argument filtering.
The filterDeadArgs function takes a list of dead argument indices--ordered from least to greatest--a list of original arguments, and produces a list of arguments excluding the arguments at those dead indices. It does that by iterating from 0 to size(originalArguments) - 1, adding the original argument at that index to the list of new arguments, so long as the index that of a dead argument. To avoid doing lookups into a set, this relies on the dead arguments being ordered ascending. There is an interator into the dead argument list that is incremented only when the current index is dead. When that iterator is at the end, dereferencing it just gives the size of the array of dead arguments. So in the case where the first argument is dead but no other arguments are, and there _are_ other arguments, the first argument would be skipped, and the second argument's index would be found to be equal to the dereferenced iterator (1). Previously, there was no check that the iterator was not at the end. The result was failing to add the second argument to the new list. And tripping an assertion failure. Here, it is checked that the iterator is not at the end.
1 parent 20400f4 commit 81d37be

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ static void filterDeadArgs(OperandValueArrayRef origArgs,
34093409
SmallVectorImpl<SILValue> &newArgs) {
34103410
auto nextDeadArgI = deadArgIndices.begin();
34113411
for (unsigned i : indices(origArgs)) {
3412-
if (i == *nextDeadArgI) {
3412+
if (i == *nextDeadArgI && nextDeadArgI != deadArgIndices.end()) {
34133413
++nextDeadArgI;
34143414
continue;
34153415
}

test/SILOptimizer/address_lowering_phi.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ enum Optional<T> {
1515
case some(T)
1616
}
1717

18+
struct S {}
19+
1820
struct SRef<T> {
1921
@_hasStorage var object: AnyObject { get set }
2022
@_hasStorage var element: T { get set }
@@ -517,3 +519,20 @@ exit(%self_2 : @owned $Self):
517519
%retval = tuple ()
518520
return %retval : $()
519521
}
522+
523+
// Check deleting the first of multiple block arguments.
524+
// CHECK-LABEL: sil [ossa] @f110_nonfinal_argument : {{.*}} {
525+
// CHECK: bb3({{%[^,]+}} : $S):
526+
// CHECK-LABEL: } // end sil function 'f110_nonfinal_argument'
527+
sil [ossa] @f110_nonfinal_argument : $@convention(thin) <T> (@in T, S) -> () {
528+
entry(%instance : @owned $T, %s : $S):
529+
cond_br undef, left, right
530+
left:
531+
br exit(%instance : $T, %s : $S)
532+
right:
533+
br exit(%instance : $T, %s : $S)
534+
exit(%instance_2 : @owned $T, %s_2 : $S):
535+
destroy_value %instance_2 : $T
536+
%retval = tuple ()
537+
return %retval : $()
538+
}

0 commit comments

Comments
 (0)