1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
// RUN: %target-sil-opt %s -verify-continue-on-failure=true -o /dev/null 2>&1 | %FileCheck %s
import Builtin
class Klass {}
sil @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
// Write: store {{.*}} [assign] {{.*}}
// CHECK: Begin Error in function test_write_reborrow
// CHECK: SIL verification failed: Found load borrow that is invalidated by a local write?!: loadBorrowImmutabilityAnalysis.isImmutable(LBI)
// CHECK: End Error in function test_write_reborrow
sil [ossa] @test_write_reborrow : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack [lexical] $Klass
store %0 to [init] %stk : $*Klass
%ld1 = load_borrow %stk : $*Klass
br bb2(%ld1 : $Klass)
bb2(%ld : @guaranteed $Klass):
store %1 to [assign] %stk : $*Klass
%3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
%4 = apply %3(%ld) : $@convention(thin) (@guaranteed Klass) -> ()
end_borrow %ld : $Klass
destroy_addr %stk : $*Klass
dealloc_stack %stk : $*Klass
%6 = tuple ()
return %6 : $()
}
// CHECK: Write: destroy_addr %2 : $*Klass
// CHECK: Begin Error in function test_multiple_loadborrows
// CHECK: SIL verification failed: Found load borrow that is invalidated by a local write?!: loadBorrowImmutabilityAnalysis.isImmutable(LBI)
// CHECK: Verifying instruction:
// CHECK: %2 = alloc_stack [lexical] $Klass
// CHECK: -> %14 = load_borrow %2 : $*Klass
// CHECK: br bb6(%14 : $Klass)
// CHECK: End Error in function test_multiple_loadborrows
sil [ossa] @test_multiple_loadborrows : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack [lexical] $Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %1 : $Klass
store %0 to [init] %stk : $*Klass
br bb3
bb2:
destroy_value %0 : $Klass
store %1 to [init] %stk : $*Klass
br bb3
bb3:
cond_br undef, bb4, bb5
bb4:
%ld1 = load_borrow %stk : $*Klass
destroy_addr %stk : $*Klass
br bb6(%ld1 : $Klass)
bb5:
%ld2 = load_borrow %stk : $*Klass
destroy_addr %stk : $*Klass
br bb6(%ld2 : $Klass)
bb6(%ld : @guaranteed $Klass):
%3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
%4 = apply %3(%ld) : $@convention(thin) (@guaranteed Klass) -> ()
end_borrow %ld : $Klass
dealloc_stack %stk : $*Klass
%6 = tuple ()
return %6 : $()
}
struct ArrayIntBuffer {
var storage : Builtin.NativeObject
}
struct MyArray<T> {
var buffer : ArrayIntBuffer
}
struct MyStruct {
}
// CHECK: Write: %4 = is_unique %1 : $*ArrayIntBuffer
// CHECK: Begin Error in function test_is_unique
// CHECK: SIL verification failed: Found load borrow that is invalidated by a local write?!: loadBorrowImmutabilityAnalysis.isImmutable(LBI)
// CHECK: End Error in function test_is_unique
sil [ossa] @test_is_unique : $@convention(thin) (@in MyArray<MyStruct>) -> () {
bb0(%0 : $*MyArray<MyStruct>):
%1 = struct_element_addr %0 : $*MyArray<MyStruct>, #MyArray.buffer
%2 = load_borrow %1 : $*ArrayIntBuffer
%3 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
%6 = is_unique %1 : $*ArrayIntBuffer
%7 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
end_borrow %2 : $ArrayIntBuffer
destroy_addr %0 : $*MyArray<MyStruct>
%t = tuple ()
return %t : $()
}
|