Skip to content

Commit 883d145

Browse files
committed
Handle nil BorrowedValue during canonicalization
1 parent 87a7d22 commit 883d145

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CanonicalizeBorrowScope {
136136

137137
protected:
138138
void initBorrow(BorrowedValue borrow) {
139-
assert(liveness.empty() && persistentCopies.empty());
139+
assert(borrow && liveness.empty() && persistentCopies.empty());
140140

141141
updatedCopies.clear();
142142
borrowedValue = borrow;

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,13 @@ bool CanonicalizeBorrowScope::consolidateBorrowScope() {
778778

779779
bool CanonicalizeBorrowScope::canonicalizeFunctionArgument(
780780
SILFunctionArgument *arg) {
781-
LLVM_DEBUG(llvm::dbgs() << "*** Canonicalize Borrow: " << borrowedValue);
781+
BorrowedValue borrow(arg);
782+
if (!borrow)
783+
return false;
782784

783-
initBorrow(BorrowedValue(arg));
785+
initBorrow(borrow);
786+
787+
LLVM_DEBUG(llvm::dbgs() << "*** Canonicalize Borrow: " << borrowedValue);
784788

785789
SWIFT_DEFER { liveness.clear(); };
786790

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,10 +5091,10 @@ bb0(%0 : @guaranteed $Function):
50915091

50925092
sil [reabstraction_thunk] @thunk : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> ()
50935093

5094-
// CHECK-LABEL: sil [ossa] @test_partial_apply_apply_opt :
5094+
// CHECK-LABEL: sil [ossa] @test_partial_apply_apply_opt1 :
50955095
// CHECK-NOT: partial_apply
5096-
// CHECK: } // end sil function 'test_partial_apply_apply_opt'
5097-
sil [ossa] @test_partial_apply_apply_opt : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () {
5096+
// CHECK: } // end sil function 'test_partial_apply_apply_opt1'
5097+
sil [ossa] @test_partial_apply_apply_opt1 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () {
50985098
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
50995099
%c1 = copy_value %0 : $Klass
51005100
%c2 = copy_value %1 : $Klass
@@ -5106,3 +5106,20 @@ bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
51065106
return %7 : $()
51075107
}
51085108

5109+
// CHECK-LABEL: sil [ossa] @test_partial_apply_apply_opt2 :
5110+
// CHECK-NOT: partial_apply
5111+
// CHECK: } // end sil function 'test_partial_apply_apply_opt2'
5112+
sil [ossa] @test_partial_apply_apply_opt2 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
5113+
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
5114+
%c1 = copy_value %0 : $Klass
5115+
%c2 = copy_value %1 : $Klass
5116+
%f1 = function_ref @thunk : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> ()
5117+
%p1 = partial_apply [callee_guaranteed] %f1(%c1, %c2) : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> ()
5118+
%r = apply %p1() : $@callee_guaranteed () -> ()
5119+
destroy_value %p1 : $@callee_guaranteed () -> ()
5120+
destroy_value %0 : $Klass
5121+
destroy_value %1 : $Klass
5122+
%7 = tuple ()
5123+
return %7 : $()
5124+
}
5125+

0 commit comments

Comments
 (0)