Skip to content

Commit 4115aad

Browse files
authored
Merge pull request #14706 from gottesmm/pr-83c2e2a697bb24954535bcb0cd68e119abae9e40
2 parents 0661de2 + d390308 commit 4115aad

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,11 +1921,16 @@ bool SILValueOwnershipChecker::checkValueWithoutLifetimeEndingUses() {
19211921

19221922
if (!isValueAddressOrTrivial(Value, Mod)) {
19231923
return !handleError([&] {
1924-
llvm::errs() << "Function: '" << Value->getFunction()->getName() << "'\n"
1925-
<< "Non trivial values, non address values, and non "
1926-
"guaranteed function args must have at least one "
1927-
"lifetime ending use?!\n"
1928-
<< "Value: " << *Value << '\n';
1924+
llvm::errs() << "Function: '" << Value->getFunction()->getName() << "'\n";
1925+
if (Value.getOwnershipKind() == ValueOwnershipKind::Owned) {
1926+
llvm::errs() << "Error! Found a leaked owned value that was never "
1927+
"consumed.\n";
1928+
} else {
1929+
llvm::errs() << "Non trivial values, non address values, and non "
1930+
"guaranteed function args must have at least one "
1931+
"lifetime ending use?!\n";
1932+
}
1933+
llvm::errs() << "Value: " << *Value << '\n';
19291934
});
19301935
}
19311936

test/SIL/ownership-verifier/leaks.sil

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)