|
| 1 | +// RUN: %target-sil-opt -sil-ownership-verifier-enable-testing -enable-sil-verify-all=0 -o /dev/null 2>&1 %s | %FileCheck %s |
| 2 | +// REQUIRES: asserts |
| 3 | + |
| 4 | +// This file tests that when we emit an error, it is a true negative. This is |
| 5 | +// done by parsing the emitted output from the ownership verifier. |
| 6 | + |
| 7 | +import Builtin |
| 8 | + |
| 9 | + |
| 10 | +sil [ossa] @coroutine_callee : $@yield_once (@guaranteed Builtin.NativeObject) -> () { |
| 11 | +bb0(%0 : @guaranteed $Builtin.NativeObject): |
| 12 | + yield (), resume bb1, unwind bb2 |
| 13 | + |
| 14 | +bb1: |
| 15 | + %r = tuple () |
| 16 | + return %r : $() |
| 17 | + |
| 18 | +bb2: |
| 19 | + unwind |
| 20 | +} |
| 21 | + |
| 22 | +// CHECK-LABEL: Function: 'destroy_value_before_end_borrow' |
| 23 | +// CHECK: Found use after free?! |
| 24 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 25 | +// CHECK: Consuming User: destroy_value %0 : $Builtin.NativeObject |
| 26 | +// CHECK: Non Consuming User: end_borrow %1 : $Builtin.NativeObject |
| 27 | +// CHECK: Block: bb0 |
| 28 | +sil [ossa] @destroy_value_before_end_borrow : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 29 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 30 | + %1 = begin_borrow %0 : $Builtin.NativeObject |
| 31 | + destroy_value %0 : $Builtin.NativeObject |
| 32 | + end_borrow %1 : $Builtin.NativeObject |
| 33 | + %9999 = tuple() |
| 34 | + return %9999 : $() |
| 35 | +} |
| 36 | + |
| 37 | +// CHECK-LABEL: Function: 'destroy_value_before_end_borrow_coroutine' |
| 38 | +// CHECK: Found use after free?! |
| 39 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 40 | +// CHECK: Consuming User: destroy_value %0 : $Builtin.NativeObject |
| 41 | +// CHECK: Non Consuming User: end_apply %2 |
| 42 | +// CHECK: Block: bb0 |
| 43 | +sil [ossa] @destroy_value_before_end_borrow_coroutine : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 44 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 45 | + %coro = function_ref @coroutine_callee : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 46 | + %token = begin_apply %coro(%0) : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 47 | + destroy_value %0 : $Builtin.NativeObject |
| 48 | + end_apply %token |
| 49 | + %r = tuple () |
| 50 | + return %r : $() |
| 51 | +} |
| 52 | + |
| 53 | +// CHECK-LABEL: Function: 'destroy_value_before_end_borrow_coroutine_2' |
| 54 | +// CHECK: Found use after free?! |
| 55 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 56 | +// CHECK: Consuming User: destroy_value %0 : $Builtin.NativeObject |
| 57 | +// CHECK: Non Consuming User: abort_apply %2 |
| 58 | +// CHECK: Block: bb0 |
| 59 | +sil [ossa] @destroy_value_before_end_borrow_coroutine_2 : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 60 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 61 | + %coro = function_ref @coroutine_callee : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 62 | + %token = begin_apply %coro(%0) : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 63 | + destroy_value %0 : $Builtin.NativeObject |
| 64 | + abort_apply %token |
| 65 | + %r = tuple () |
| 66 | + return %r : $() |
| 67 | +} |
| 68 | + |
| 69 | +// CHECK-LABEL: Function: 'destroy_value_before_end_borrow_coroutine_3' |
| 70 | +// CHECK: Found use after free?! |
| 71 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 72 | +// CHECK: Consuming User: destroy_value %0 : $Builtin.NativeObject |
| 73 | +// CHECK: Non Consuming User: abort_apply %2 |
| 74 | +// CHECK: Block: bb1 |
| 75 | + |
| 76 | +// CHECK-LABEL: Function: 'destroy_value_before_end_borrow_coroutine_3' |
| 77 | +// CHECK: Found use after free due to unvisited non lifetime ending uses?! |
| 78 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 79 | +// CHECK: Remaining Users: |
| 80 | +// CHECK: User: abort_apply %2 |
| 81 | +// CHECK: Block: bb1 |
| 82 | + |
| 83 | +sil [ossa] @destroy_value_before_end_borrow_coroutine_3 : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 84 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 85 | + %coro = function_ref @coroutine_callee : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 86 | + %token = begin_apply %coro(%0) : $@yield_once @convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 87 | + cond_br undef, bb1, bb2 |
| 88 | + |
| 89 | +bb1: |
| 90 | + destroy_value %0 : $Builtin.NativeObject |
| 91 | + abort_apply %token |
| 92 | + br bb3 |
| 93 | + |
| 94 | +bb2: |
| 95 | + end_apply %token |
| 96 | + destroy_value %0 : $Builtin.NativeObject |
| 97 | + br bb3 |
| 98 | + |
| 99 | +bb3: |
| 100 | + %r = tuple () |
| 101 | + return %r : $() |
| 102 | +} |
0 commit comments