Skip to content

Commit abbd9d3

Browse files
committed
OSSALifetimeCompletion: need to look through borrowed-from when creating an end_borrow
Fixes a verifier crash rdar://134728428
1 parent b3c13e4 commit abbd9d3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/SIL/Utils/OSSALifetimeCompletion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static SILInstruction *endOSSALifetime(SILValue value,
7676
}
7777
return builder.createDestroyValue(loc, value, DontPoisonRefs, isDeadEnd);
7878
}
79-
return builder.createEndBorrow(loc, value);
79+
return builder.createEndBorrow(loc, lookThroughBorrowedFromUser(value));
8080
}
8181

8282
static bool endLifetimeAtLivenessBoundary(SILValue value,

test/SILOptimizer/ossa_lifetime_completion.sil

+29
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,32 @@ backedge2(%c2 : @owned $C, %b2 : @reborrow @guaranteed $C):
763763
exit:
764764
unreachable
765765
}
766+
767+
768+
// CHECK-LABEL: begin running test {{.*}} on test_borrowed_from: ossa_lifetime_completion
769+
// CHECK-LABEL: sil [ossa] @test_borrowed_from : {{.*}} {
770+
// CHECK: bb1([[A:%.*]] : @reborrow @guaranteed $C):
771+
// CHECK: [[BF:%.*]] = borrowed [[A]] : $C from (%0 : $C)
772+
// CHECK: bb2:
773+
// CHECK-NEXT: end_borrow [[BF]] : $C
774+
// CHECK-NEXT: unreachable
775+
// CHECK-LABEL: } // end sil function 'test_borrowed_from'
776+
// CHECK-LABEL: end running test {{.*}} on test_borrowed_from: ossa_lifetime_completion
777+
sil [ossa] @test_borrowed_from : $@convention(thin) (@owned C) -> @owned C {
778+
bb0(%0 : @owned $C):
779+
%1 = begin_borrow %0 : $C
780+
br bb1(%1 : $C)
781+
782+
bb1(%3 : @reborrow @guaranteed $C):
783+
%4 = borrowed %3 : $C from (%0 : $C)
784+
specify_test "ossa_lifetime_completion %3 availability"
785+
cond_br undef, bb2, bb3
786+
787+
bb2:
788+
unreachable
789+
790+
bb3:
791+
end_borrow %4 : $C
792+
return %0 : $C
793+
}
794+

0 commit comments

Comments
 (0)