|
| 1 | +// RUN: %target-sil-opt -module-name Swift -sil-ownership-verifier-enable-testing -enable-sil-ownership -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s |
| 2 | +// REQUIRES: asserts |
| 3 | + |
| 4 | +// This file is meant to contain dataflow tests that are true leaks. It is |
| 5 | +// intended to test both that we are failing and that we are emitting |
| 6 | +// appropriate error messages. |
| 7 | + |
| 8 | +////////////////// |
| 9 | +// Declarations // |
| 10 | +////////////////// |
| 11 | + |
| 12 | +sil_stage canonical |
| 13 | + |
| 14 | +import Builtin |
| 15 | + |
| 16 | +/////////// |
| 17 | +// Tests // |
| 18 | +/////////// |
| 19 | + |
| 20 | +// CHECK-LABEL: Function: 'owned_never_consumed' |
| 21 | +// CHECK: Error! Found a leaked owned value that was never consumed. |
| 22 | +// CHECK: Value: %1 = copy_value %0 : $Builtin.NativeObject |
| 23 | +sil @owned_never_consumed : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () { |
| 24 | +bb0(%0 : @guaranteed $Builtin.NativeObject): |
| 25 | + %1 = copy_value %0 : $Builtin.NativeObject |
| 26 | + %9999 = tuple() |
| 27 | + return %9999 : $() |
| 28 | +} |
| 29 | + |
| 30 | +// CHECK-LABEL: Function: 'owned_leaks_along_one_path' |
| 31 | +// CHECK: Error! Found a leak due to a consuming post-dominance failure! |
| 32 | +// CHECK: Value: %0 = argument of bb0 : $Builtin.NativeObject |
| 33 | +// CHECK: Post Dominating Failure Blocks: |
| 34 | +// CHECK: bb1 |
| 35 | +sil @owned_leaks_along_one_path : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 36 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 37 | + cond_br undef, bb1, bb2 |
| 38 | + |
| 39 | +bb1: |
| 40 | + br bb3 |
| 41 | + |
| 42 | +bb2: |
| 43 | + destroy_value %0 : $Builtin.NativeObject |
| 44 | + br bb3 |
| 45 | + |
| 46 | +bb3: |
| 47 | + %9999 = tuple() |
| 48 | + return %9999 : $() |
| 49 | +} |
| 50 | + |
| 51 | +// Make sure that we report the leak at the phi. |
| 52 | +// CHECK-LABEL: Function: 'owned_leaks_with_phi' |
| 53 | +// CHECK: Error! Found a leaked owned value that was never consumed. |
| 54 | +// CHECK: Value: %6 = argument of bb4 : $Builtin.NativeObject |
| 55 | +sil @owned_leaks_with_phi : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 56 | +bb0(%0 : @owned $Builtin.NativeObject): |
| 57 | + br bb1(%0 : $Builtin.NativeObject) |
| 58 | + |
| 59 | +bb1(%1 : @owned $Builtin.NativeObject): |
| 60 | + cond_br undef, bb3, bb2 |
| 61 | + |
| 62 | +bb2: |
| 63 | + br bb4(%1 : $Builtin.NativeObject) |
| 64 | + |
| 65 | +bb3: |
| 66 | + br bb1(%1 : $Builtin.NativeObject) |
| 67 | + |
| 68 | +bb4(%2 : @owned $Builtin.NativeObject): |
| 69 | + %9999 = tuple() |
| 70 | + return %9999 : $() |
| 71 | +} |
0 commit comments