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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// RUN: %target-sil-opt -module-name Swift -enable-sil-verify-all=0 -o /dev/null %s 2>&1
// REQUIRES: asserts
// This file is meant to contain dataflow tests that if they fail are false
// positives.
//////////////////
// Declarations //
//////////////////
sil_stage canonical
import Builtin
protocol Error {}
sil @in_guaranteed_user : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
sil @error_func : $@convention(thin) () -> (Builtin.Int32, @error Error)
sil @allocate_object : $@convention(thin) () -> (@owned Builtin.NativeObject)
///////////
// Tests //
///////////
sil [ossa] @leak_loop_test : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
%1 = alloc_stack $Builtin.NativeObject
%2 = begin_borrow %0 : $Builtin.NativeObject
%sbi = store_borrow %2 to %1 : $*Builtin.NativeObject
%3 = function_ref @in_guaranteed_user : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
apply %3(%sbi) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
end_borrow %sbi : $*Builtin.NativeObject
end_borrow %2 : $Builtin.NativeObject
dealloc_stack %1 : $*Builtin.NativeObject
br bb1
bb1:
cond_br undef, bb2, bb5
bb2:
cond_br undef, bb3, bb4
bb3:
br bb1
bb4:
br bb1
bb5:
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// This test makes sure in the context of arguments, that if we have one
// lifetime ending user and that lifetime ending user is in the same block as
// the producer, we do not consider the predecessor blocks where our value is
// not defined. In the following test case, the bad predecessor is bb0.
sil [ossa] @single_block_consume_with_arg_and_unreachable : $@convention(thin) () -> () {
bb0:
%0 = function_ref @error_func : $@convention(thin) () -> (Builtin.Int32, @error Error)
try_apply %0() : $@convention(thin) () -> (Builtin.Int32, @error Error), normal bb1, error bb2
bb1(%2 : $Builtin.Int32):
%9999 = tuple()
return %9999 : $()
bb2(%3 : @owned $Error):
destroy_value %3 : $Error
unreachable
}
// This test makes sure in the context of instructions that produce new owned
// values, that if we have one lifetime ending user and that lifetime ending
// user is in the same block as the producer, we do not consider the predecessor
// blocks where our value is not defined. In the following test case, the bad
// predecessor is bb0.
sil [ossa] @single_block_consume_with_allocated_arg_and_unreachable : $@convention(thin) () -> () {
bb0:
cond_br undef, bb1, bb2
bb1:
%9999 = tuple()
return %9999 : $()
bb2:
%0 = function_ref @allocate_object : $@convention(thin) () -> (@owned Builtin.NativeObject)
%1 = apply %0() : $@convention(thin) () -> (@owned Builtin.NativeObject)
destroy_value %1 : $Builtin.NativeObject
unreachable
}
// This test makes sure in the context of instructions in a diamond that produce
// new owned values, that if we have one lifetime ending user and that lifetime
// ending user is in the same block as the producer, we do not consider the
// predecessor blocks where our value is not defined. In the following test
// case, the bad predecessor is bb0.
sil [ossa] @single_block_consume_with_diamond : $@convention(thin) () -> () {
bb0:
cond_br undef, bb1, bb2
bb1:
br bb3
bb2:
%0 = function_ref @allocate_object : $@convention(thin) () -> (@owned Builtin.NativeObject)
%1 = apply %0() : $@convention(thin) () -> (@owned Builtin.NativeObject)
destroy_value %1 : $Builtin.NativeObject
br bb3
bb3:
%9999 = tuple()
return %9999 : $()
}
// This test makes sure that we do not consider successors of our lifetime
// ending users as successors that we must visit. The target block is bb4.
sil [ossa] @multiple_block_consume_with_diamond : $@convention(thin) () -> () {
bb0:
cond_br undef, bb1, bb5
bb1:
%0 = function_ref @allocate_object : $@convention(thin) () -> (@owned Builtin.NativeObject)
%1 = apply %0() : $@convention(thin) () -> (@owned Builtin.NativeObject)
cond_br undef, bb2, bb3
bb2:
destroy_value %1 : $Builtin.NativeObject
br bb6
bb3:
destroy_value %1 : $Builtin.NativeObject
br bb4
bb4:
br bb6
bb5:
br bb6
bb6:
%9999 = tuple()
return %9999 : $()
}
|