Skip to content

Commit a4c970f

Browse files
committed
Add unsafeAddress dependency SILGen test case
1 parent b56a787 commit a4c970f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
public class C {}
4+
5+
public struct BoxC {
6+
let storage: AnyObject?
7+
let pointer: UnsafePointer<C>
8+
9+
subscript() -> C {
10+
unsafeAddress {
11+
pointer
12+
}
13+
}
14+
}
15+
16+
// The addressor result must explicitly dependend on the apply's 'self' arg.
17+
//
18+
// CHECK-LABEL: sil [ossa] @$s20addressor_dependence21testAddressorLifetime3boxAA1CCAA4BoxCVn_tF : $@convention(thin) (@owned BoxC) -> @owned C {
19+
// CHECK: bb0(%0 : @noImplicitCopy @_eagerMove @owned $BoxC):
20+
// CHECK: [[MV:%.*]] = moveonlywrapper_to_copyable [guaranteed]
21+
// CHECK: [[APPLY:%.*]] = apply %{{.*}}([[MV]]) : $@convention(method) (@guaranteed BoxC) -> UnsafePointer<C>
22+
// CHECK: [[P:%.*]] = struct_extract [[APPLY]], #UnsafePointer._rawValue
23+
// CHECK: [[A:%.*]] = pointer_to_address [[P]] to [strict] $*C
24+
// CHECK: [[MD:%.*]] = mark_dependence [unresolved] [[A]] on [[MV]]
25+
// CHECK: begin_access [read] [unsafe] [[MD]]
26+
// CHECK-LABEL: } // end sil function '$s20addressor_dependence21testAddressorLifetime3boxAA1CCAA4BoxCVn_tF'
27+
public func testAddressorLifetime(box: consuming BoxC) -> C {
28+
box[]
29+
}

0 commit comments

Comments
 (0)