Skip to content

Commit ad5bae4

Browse files
authored
Merge pull request #29537 from atrick/5.2-fix-guaranteed-phi
[5.2]Fix propagation of guaranteed phi args during DiagnoseUnreachable.
2 parents dfd6d1c + d977b4e commit ad5bae4

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
185185
// this to CCP and trigger another round of copy propagation.
186186
SILArgument *Arg = *AI;
187187

188-
// If this argument is guaranteed and Args[Idx] is a SILFunctionArgument,
189-
// delete the end_borrow.
190-
if (Arg->getOwnershipKind() == ValueOwnershipKind::Guaranteed &&
191-
isa<SILFunctionArgument>(Args[Idx])) {
188+
// If this argument is guaranteed and Args[Idx], delete the end_borrow.
189+
if (Arg->getOwnershipKind() == ValueOwnershipKind::Guaranteed)
192190
deleteEndBorrows(Arg);
193-
}
194191

195192
// We were able to fold, so all users should use the new folded value.
196193
Arg->replaceAllUsesWith(Args[Idx]);

test/SILOptimizer/diagnose_unreachable.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,33 @@ bb2:
760760
%9999 = tuple()
761761
return %9999 : $()
762762
}
763+
764+
// Test propagation of guaranteed phi arguments. The nested end_borrow
765+
// must be removed, even with the outer borrow is *not* a function
766+
// argument.
767+
768+
enum EnumWithB {
769+
case A(B)
770+
func testit() -> Int
771+
}
772+
773+
// CHECK-LABEL: sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
774+
// CHECK: bb1([[PHI:%.*]] : @guaranteed $B):
775+
// CHECK: br bb2
776+
// CHECK: bb2:
777+
// CHECK: end_borrow [[PHI]] : $B
778+
// CHECK-NOT: end_borrow
779+
// CHECK-LABEL: } // end sil function 'testPropagateGuaranteedPhi'
780+
sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
781+
bb0(%0 : @guaranteed $EnumWithB):
782+
switch_enum %0 : $EnumWithB, case #EnumWithB.A!enumelt.1: bb1
783+
784+
bb1(%2 : @guaranteed $B):
785+
br bb3(%2 : $B)
786+
787+
bb3(%4 : @guaranteed $B):
788+
end_borrow %4 : $B
789+
end_borrow %2 : $B
790+
%99 = tuple ()
791+
return %99 : $()
792+
}

0 commit comments

Comments
 (0)