Skip to content

Commit

Permalink
Clear context in ownership rauw when we cannot fix ownership for rauw.
Browse files Browse the repository at this point in the history
If not, subsequent unrelated call of OwnershipRAUWHelper::perform will have stale
entries for transitiveBorrowedUses etc
  • Loading branch information
meg-gupta committed Jan 27, 2021
1 parent 3e330ab commit 78a6213
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/SILOptimizer/Utils/OwnershipOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue,
if (oldValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
// Check that the old lifetime can be extended and record the necessary
// book-keeping in the OwnershipFixupContext.
return findTransitiveBorrowedUses(oldValue, context.transitiveBorrowedUses,
context.recursiveReborrows);
if (!findTransitiveBorrowedUses(oldValue, context.transitiveBorrowedUses,
context.recursiveReborrows)) {
context.clear();
return false;
}
}
return true;
}
Expand Down
31 changes: 31 additions & 0 deletions test/SILOptimizer/cse_ossa_nontrivial.sil
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,34 @@ bb3(%borrow : @guaranteed $Klass):
return %copy : $NonTrivialStruct
}

// Test to make sure we clear the context if we fail while checking if ownership rauw is possible
// CHECK-LABEL: sil [ossa] @test_rauwfailsandthensucceeds :
// CHECK: bb0
// CHECK: struct_extract
// CHECK: struct_extract
// CHECK: struct $_SliceBuffer
// CHECK-NOT: struct $_SliceBuffer
// CHECK-LABEL: } // end sil function 'test_rauwfailsandthensucceeds'
sil [ossa] @test_rauwfailsandthensucceeds : $@convention(method) <Element> (UnsafeMutablePointer<Element>, @guaranteed _ContiguousArrayBuffer<Element>, Int, UInt) -> @owned _SliceBuffer<Element> {
bb0(%0 : $UnsafeMutablePointer<Element>, %1 : @guaranteed $_ContiguousArrayBuffer<Element>, %2 : $Int, %3 : $UInt):
%4 = struct_extract %1 : $_ContiguousArrayBuffer<Element>, #_ContiguousArrayBuffer._storage
%5 = copy_value %4 : $__ContiguousArrayStorageBase
%6 = init_existential_ref %5 : $__ContiguousArrayStorageBase : $__ContiguousArrayStorageBase, $AnyObject
%7 = struct_extract %1 : $_ContiguousArrayBuffer<Element>, #_ContiguousArrayBuffer._storage
%8 = ref_tail_addr %7 : $__ContiguousArrayStorageBase, $Element
%9 = address_to_pointer %8 : $*Element to $Builtin.RawPointer
%10 = struct $UnsafeMutablePointer<Element> (%9 : $Builtin.RawPointer)
%11 = begin_borrow %6 : $AnyObject
%12 = struct $_SliceBuffer<Element> (%11 : $AnyObject, %0 : $UnsafeMutablePointer<Element>, %2 : $Int, %3 : $UInt)
%13 = copy_value %12 : $_SliceBuffer<Element>
end_borrow %11 : $AnyObject
destroy_value %13 : $_SliceBuffer<Element>
%14 = begin_borrow %6 : $AnyObject
%15 = struct $_SliceBuffer<Element> (%14 : $AnyObject, %0 : $UnsafeMutablePointer<Element>, %2 : $Int, %3 : $UInt)
%16 = copy_value %15 : $_SliceBuffer<Element>
end_borrow %14 : $AnyObject
%17 = struct $_SliceBuffer<Element> (%6 : $AnyObject, %0 : $UnsafeMutablePointer<Element>, %2 : $Int, %3 : $UInt)
destroy_value %17 : $_SliceBuffer<Element>
return %16 : $_SliceBuffer<Element>
}

0 comments on commit 78a6213

Please sign in to comment.