Skip to content

Commit 8f2df67

Browse files
committed
[RawSILLowering] InitAccessors: guard against situations when emitBeginBorrowOperation returns back original value
Calling `emitBeginBorrowOperation` on something which is `load_borrow` for example with guaranteed ownership doesn't produce `begin_borrow` instruction, so we need to be careful not to emit mismatched `end_borrow` in such cases.
1 parent 49fcce8 commit 8f2df67

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ lowerAssignOrInitInstruction(SILBuilderWithScope &b,
337337
b.createApply(loc, initFn, SubstitutionMap(), arguments);
338338

339339
if (isRefSelf) {
340-
b.emitEndBorrowOperation(loc, selfRef);
340+
if (selfRef != selfValue)
341+
b.emitEndBorrowOperation(loc, selfRef);
341342
} else {
342343
b.createEndAccess(loc, selfRef, /*aborted=*/false);
343344
}

0 commit comments

Comments
 (0)