Skip to content

Commit c6f7a92

Browse files
committed
Add and update lifetime_dependence unit tests.
1 parent 3787044 commit c6f7a92

File tree

7 files changed

+223
-122
lines changed

7 files changed

+223
-122
lines changed

test/SILGen/addressors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func test1() -> Int32 {
102102
// CHECK: [[PTR:%.*]] = apply [[ACCESSOR]]({{%.*}}, [[A]]) : $@convention(method) (Int32, A) -> UnsafePointer<Int32>
103103
// CHECK: [[T0:%.*]] = struct_extract [[PTR]] : $UnsafePointer<Int32>, #UnsafePointer._rawValue
104104
// CHECK: [[T1:%.*]] = pointer_to_address [[T0]] : $Builtin.RawPointer to [strict] $*Int32
105-
// CHECK: [[MD:%.*]] = mark_dependence [[T1]] : $*Int32 on [[A]] : $A
105+
// CHECK: [[MD:%.*]] = mark_dependence [nonescaping] [[T1]] : $*Int32 on [[A]] : $A
106106
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unsafe] [[MD]] : $*Int32
107107
// CHECK: [[T2:%.*]] = load [[ACCESS]] : $*Int32
108108
// CHECK: return [[T2]] : $Int32

test/SILOptimizer/lifetime_dependence/diagnostic_passes.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %target-sil-opt -test-runner %s \
1+
// RUN: %target-sil-opt %s \
22
// RUN: -diagnostics -sil-verify-all \
33
// RUN: -enable-experimental-feature LifetimeDependence \
44
// RUN: -enable-experimental-feature Span \
5-
// RUN: 2>&1 | %FileCheck %s
5+
// RUN: | %FileCheck %s
66

77
// Test SIL expected from SILGen output. Run all diagnostic passes which includes lifetime dependence handling:
88
// -lifetime-dependence-insertion

test/SILOptimizer/lifetime_dependence/lifetime_dependence_scope.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/SILOptimizer/lifetime_dependence/lifetime_dependence_util.sil

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ entry(%0 : @owned $C, %1 : @owned $D, %2 : @guaranteed $D, %3 : $*D, %4 : $*D):
133133
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %trivial_mark
134134
// CHECK-NEXT: Unknown: %{{.*}} = integer_literal $Builtin.Int1, 0
135135
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping]
136-
// CHECK-NEXT: begin: %{{.*}} = integer_literal $Builtin.Int1, 0
137-
// CHECK-NEXT: ends:{{[ ]+$}}
136+
// CHECK-NEXT: Caller range
138137
// CHECK: dependence_scope: lifetime_dependence_scope with: %trivial_mark
139138

140139
%f = ref_element_addr %borrow : $D, #D.object
@@ -166,8 +165,10 @@ entry(%0 : @owned $C, %1 : @owned $D, %2 : @guaranteed $D, %3 : $*D, %4 : $*D):
166165

167166
%inout_arg_mark = mark_dependence [nonescaping] %inguaranteed_arg_mark : $C on %4 : $*D
168167
specify_test "lifetime_dependence_scope %inout_arg_mark"
168+
// We do not expect a direct dependence on in inout argument. Treat it as unknown.
169+
// Instead, mutable variable access should have an access scope.
169170
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %inout_arg_mark
170-
// CHECK-NEXT: Caller: %4 = argument of bb0 : $*D
171+
// CHECK-NEXT: Unknown: %4 = argument of bb0 : $*D
171172
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %4 : $*D
172173
// CHECK: dependence_scope: lifetime_dependence_scope with: %inout_arg_mark
173174

@@ -180,37 +181,6 @@ entry(%0 : @owned $C, %1 : @owned $D, %2 : @guaranteed $D, %3 : $*D, %4 : $*D):
180181
return %99 : $()
181182
}
182183

183-
sil [ossa] @dependence_root : $@convention(thin) (@owned D, @owned C) -> () {
184-
entry(%0 : @owned $D, %1 : @owned $C):
185-
%copy = copy_value %0 : $D
186-
%move = move_value %copy : $D
187-
%borrow = begin_borrow %move : $D
188-
%d2c = upcast %borrow : $D to $C
189-
%pair = struct $PairC(%d2c : $C, %d2c : $C)
190-
%mark_pair = mark_dependence [nonescaping] %1 : $C on %pair : $PairC
191-
specify_test "lifetime_dependence_root %mark_pair"
192-
// CHECK-LABEL: dependence_root: lifetime_dependence_root with: %mark_pair
193-
// CHECK-NEXT: Scope: Owned: %0 = argument of bb0 : $D
194-
// CHECK-NEXT: dependence_root: lifetime_dependence_root with: %mark_pair
195-
196-
%f = ref_element_addr %borrow : $D, #D.object
197-
%access = begin_access [read] [static] %f : $*C
198-
%load = load [copy] %access : $*C
199-
specify_test "lifetime_dependence_root %load"
200-
// CHECK-LABEL: dependence_root: lifetime_dependence_root with: %load
201-
// CHECK-NEXT: Scope: Unknown: %{{.*}} = ref_element_addr %{{.*}} : $D, #D.object
202-
// CHECK-NEXT: dependence_root: lifetime_dependence_root with: %load
203-
204-
destroy_value %load : $C
205-
end_access %access : $*C
206-
destroy_value %mark_pair : $C
207-
end_borrow %borrow : $D
208-
destroy_value %move : $D
209-
destroy_value %0 : $D
210-
%99 = tuple()
211-
return %99 : $()
212-
}
213-
214184
// CHECK-LABEL: dependence_access: lifetime_dependence_use with: %0
215185
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $*NE
216186
// CHECK-NEXT: Leaf use: operand #0 of end_access %{{.*}} : $*NE

test/SILOptimizer/lifetime_dependence/scopefixup.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ sil @pointeeAddressor : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (
9191
// CHECK: bb0(%0 : $UnsafePointer<Int64>):
9292
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown]
9393
// CHECK: [[LD:%.*]] = load [trivial] [[ACCESS]]
94+
// CHECK: end_access [[ACCESS]]
9495
// CHECK: [[ADR:%.*]] = pointer_to_address %{{.*}} to [strict] $*Int64
9596
// CHECK: [[MD:%.*]] = mark_dependence [unresolved] [[ADR]] on [[LD]]
9697
// CHECK: [[ACCESS2:%.*]] = begin_access [read] [unsafe] [[MD]]
9798
// CHECK: end_access [[ACCESS2]]
98-
// CHECK: end_access [[ACCESS]]
9999
// CHECK-LABEL: } // end sil function 'testTrivialAccess'
100100
sil hidden [ossa] @testTrivialAccess : $@convention(thin) (UnsafePointer<Int64>) -> () {
101101
bb0(%0 : $UnsafePointer<Int64>):

0 commit comments

Comments
 (0)