|
2 | 2 | // RUN: --lifetime-dependence-diagnostics \
|
3 | 3 | // RUN: -verify \
|
4 | 4 | // RUN: -sil-verify-all \
|
5 |
| -// RUN: -module-name Swift \ |
6 | 5 | // RUN: -enable-experimental-feature Lifetimes \
|
| 6 | +// RUN: -enable-experimental-feature AddressableTypes \ |
7 | 7 | // RUN: -o /dev/null
|
8 | 8 |
|
9 | 9 | // REQUIRES: swift_in_compiler
|
10 | 10 | // REQUIRES: swift_feature_Lifetimes
|
| 11 | +// REQUIRES: swift_feature_AddressableTypes |
11 | 12 |
|
12 | 13 | // Verify diagnostics from the LifetimeDependenceDiagnostics pass.
|
13 | 14 |
|
14 | 15 | sil_stage raw
|
15 | 16 |
|
16 | 17 | import Builtin
|
17 |
| - |
18 |
| -@_marker protocol Copyable: ~Escapable {} |
19 |
| -@_marker protocol Escapable: ~Copyable {} |
| 18 | +import Swift |
| 19 | +import SwiftShims |
20 | 20 |
|
21 | 21 | class C {}
|
22 | 22 |
|
@@ -61,6 +61,14 @@ sil @getTrivialNE : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifeti
|
61 | 61 | sil @makeHolder: $@convention(method) (@thin Holder.Type) -> @owned Holder // user: %6
|
62 | 62 | sil @getGeneric : $@convention(thin) <τ_0_0 where τ_0_0 : ~Escapable> (@guaranteed Holder, @thick τ_0_0.Type) -> @lifetime(borrow 0) @out τ_0_0 // user: %12
|
63 | 63 |
|
| 64 | +@_addressableForDependencies |
| 65 | +public struct InlineInt { |
| 66 | + var i: Int |
| 67 | +} |
| 68 | +sil @globalAddress : $@convention(thin) () -> Builtin.RawPointer |
| 69 | +sil @addressInt : $@convention(thin) (@in_guaranteed InlineInt) -> @lifetime(borrow address_for_deps 0) @owned Span<Int> |
| 70 | +sil @useSpan : $@convention(thin) (@guaranteed Span<Int>) -> () |
| 71 | + |
64 | 72 | // Test returning a owned dependence on a trivial value
|
65 | 73 | sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
|
66 | 74 | entry(%0 : @guaranteed $C):
|
@@ -246,3 +254,36 @@ bb0(%0 : $*NE, %1 : $*Holder):
|
246 | 254 | %18 = tuple ()
|
247 | 255 | return %18
|
248 | 256 | }
|
| 257 | + |
| 258 | +// Test a address dependency on a trivial value temporarily copied to the stack. The value's addressable range only |
| 259 | +// extends to the dealloc_stack. |
| 260 | +// |
| 261 | +// SILGen should never generate temporary stack copies for addressable dependencies, but we need to diagnose them anyway |
| 262 | +// so that a SILGen bug does not become a miscompile. |
| 263 | +// |
| 264 | +// rdar://159680262 ([nonescapable] diagnose dependence on a temporary copy of a global array) |
| 265 | +sil hidden [noinline] [ossa] @testTrivialStackCopy : $@convention(thin) () -> () { |
| 266 | +bb0: |
| 267 | + %0 = function_ref @globalAddress : $@convention(thin) () -> Builtin.RawPointer |
| 268 | + %1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer |
| 269 | + %2 = pointer_to_address %1 to [strict] $*InlineInt |
| 270 | + %3 = begin_access [read] [dynamic] %2 // expected-note{{it depends on this scoped access to variable ''}} |
| 271 | + %4 = load [trivial] %3 |
| 272 | + end_access %3 |
| 273 | + %6 = alloc_stack $InlineInt |
| 274 | + store %4 to [trivial] %6 |
| 275 | + |
| 276 | + %8 = function_ref @addressInt : $@convention(thin) (@in_guaranteed InlineInt) -> @lifetime(borrow address_for_deps 0) @owned Span<Int> |
| 277 | + %9 = apply %8(%6) : $@convention(thin) (@in_guaranteed InlineInt) -> @lifetime(borrow address_for_deps 0) @owned Span<Int> |
| 278 | + %10 = mark_dependence [unresolved] %9 on %6 |
| 279 | + %11 = move_value [var_decl] %10 // expected-error{{lifetime-dependent value escapes its scope}} |
| 280 | + dealloc_stack %6 |
| 281 | + %13 = begin_borrow %11 |
| 282 | + |
| 283 | + %14 = function_ref @useSpan : $@convention(thin) (@guaranteed Span<Int>) -> () |
| 284 | + %15 = apply %14(%13) : $@convention(thin) (@guaranteed Span<Int>) -> () |
| 285 | + end_borrow %13 |
| 286 | + destroy_value %11 // expected-note{{this use of the lifetime-dependent value is out of scope}} |
| 287 | + %18 = tuple () |
| 288 | + return %18 |
| 289 | +} |
0 commit comments