1
1
// RUN: %target-swift-frontend -enable-sil-opaque-values -enable-sil-ownership -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen -parse-stdlib -parse-as-library -module-name Swift %s | %FileCheck %s
2
+ // RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -enable-sil-opaque-values -enable-sil-ownership -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen -parse-stdlib -parse-as-library -module-name Swift %s | %FileCheck --check-prefix=CHECK-OSX %s
2
3
3
4
public typealias AnyObject = Builtin . AnyObject
4
5
5
6
precedencegroup CastingPrecedence { }
7
+ precedencegroup AssignmentPrecedence { }
6
8
7
9
public protocol _ObjectiveCBridgeable { }
8
10
@@ -16,12 +18,12 @@ public protocol Decoder {
16
18
17
19
// Test open_existential_value ownership
18
20
// ---
19
- // CHECK-LABEL: sil @_T0s11takeDecoderBi1_s0B0_p4from_tKF : $@convention(thin) (@in Decoder) -> (Builtin.Int1, @error Builtin.NativeObject ) {
21
+ // CHECK-LABEL: sil @_T0s11takeDecoderBi1_s0B0_p4from_tKF : $@convention(thin) (@in Decoder) -> (Builtin.Int1, @error Error ) {
20
22
// CHECK: bb0(%0 : @owned $Decoder):
21
23
// CHECK: [[BORROW1:%.*]] = begin_borrow %0 : $Decoder
22
24
// CHECK: [[OPENED:%.*]] = open_existential_value [[BORROW1]] : $Decoder to $@opened("{{.*}}") Decoder
23
- // CHECK: [[WT:%.*]] = witness_method $@opened("{{.*}}") Decoder, #Decoder.unkeyedContainer!1 : <Self where Self : Decoder> (Self) -> () throws -> UnkeyedDecodingContainer, %4 : $@opened("{{.*}}") Decoder : $@convention(witness_method) <τ_0_0 where τ_0_0 : Decoder> (@in_guaranteed τ_0_0) -> (@out UnkeyedDecodingContainer, @error Builtin.NativeObject )
24
- // CHECK: try_apply [[WT]]<@opened("{{.*}}") Decoder>([[OPENED]]) : $@convention(witness_method) <τ_0_0 where τ_0_0 : Decoder> (@in_guaranteed τ_0_0) -> (@out UnkeyedDecodingContainer, @error Builtin.NativeObject ), normal bb2, error bb1
25
+ // CHECK: [[WT:%.*]] = witness_method $@opened("{{.*}}") Decoder, #Decoder.unkeyedContainer!1 : <Self where Self : Decoder> (Self) -> () throws -> UnkeyedDecodingContainer, %4 : $@opened("{{.*}}") Decoder : $@convention(witness_method) <τ_0_0 where τ_0_0 : Decoder> (@in_guaranteed τ_0_0) -> (@out UnkeyedDecodingContainer, @error Error )
26
+ // CHECK: try_apply [[WT]]<@opened("{{.*}}") Decoder>([[OPENED]]) : $@convention(witness_method) <τ_0_0 where τ_0_0 : Decoder> (@in_guaranteed τ_0_0) -> (@out UnkeyedDecodingContainer, @error Error ), normal bb2, error bb1
25
27
//
26
28
// CHECK:bb{{.*}}([[RET1:%.*]] : @owned $UnkeyedDecodingContainer):
27
29
// CHECK: end_borrow [[BORROW1]] from %0 : $Decoder, $Decoder
@@ -58,13 +60,47 @@ public func unsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
58
60
59
61
#if os(OSX)
60
62
// Test open_existential_value used in a conversion context.
63
+ // (the actual bridging call is dropped because we don't import Swift).
61
64
// ---
62
- //
65
+ // CHECK-OSX-LABEL: sil @_T0s26_unsafeDowncastToAnyObjectyXlyp04fromD0_tF : $@convention(thin) (@in Any) -> @owned AnyObject {
66
+ // CHECK-OSX: bb0(%0 : @owned $Any):
67
+ // CHECK-OSX: [[BORROW:%.*]] = begin_borrow %0 : $Any
68
+ // CHECK-OSX: [[COPY:%.*]] = copy_value [[BORROW]] : $Any
69
+ // CHECK-OSX: [[BORROW2:%.*]] = begin_borrow [[COPY]] : $Any
70
+ // CHECK-OSX: [[VAL:%.*]] = open_existential_value [[BORROW2]] : $Any to $@opened
71
+ // CHECK-OSX: [[COPY2:%.*]] = copy_value [[VAL]] : $@opened
72
+ // CHECK-OSX: destroy_value [[COPY2]] : $@opened
73
+ // CHECK-OSX: end_borrow [[BORROW2]] from [[COPY]] : $Any, $Any
74
+ // CHECK-OSX: destroy_value [[COPY]] : $Any
75
+ // CHECK-OSX: end_borrow [[BORROW]] from %0 : $Any, $Any
76
+ // CHECK-OSX: destroy_value %0 : $Any
77
+ // CHECK-OSX: return undef : $AnyObject
78
+ // CHECK-OSX-LABEL: } // end sil function '_T0s26_unsafeDowncastToAnyObjectyXlyp04fromD0_tF'
63
79
public func _unsafeDowncastToAnyObject( fromAny any: Any ) -> AnyObject {
64
80
return any as AnyObject
65
81
}
66
82
#endif
67
83
84
+ public protocol Error { }
85
+
86
+ #if os(OSX)
87
+ // Test open_existential_box_value in a conversion context.
88
+ // ---
89
+ // CHECK-OSX-LABEL: sil @_T0s3fooys5Error_pSg1e_tF : $@convention(thin) (@owned Optional<Error>) -> () {
90
+ // CHECK-OSX: [[BORROW:%.*]] = begin_borrow %{{.*}} : $Error
91
+ // CHECK-OSX: [[VAL:%.*]] = open_existential_box_value [[BORROW]] : $Error to $@opened
92
+ // CHECK-OSX: [[COPY:%.*]] = copy_value [[VAL]] : $@opened
93
+ // CHECK-OSX: [[ANY:%.*]] = init_existential_value [[COPY]] : $@opened
94
+ // CHECK-OSX: end_borrow [[BORROW]] from %{{.*}} : $Error, $Error
95
+ // CHECK-OSX-LABEL: } // end sil function '_T0s3fooys5Error_pSg1e_tF'
96
+ public func foo( e: Error ? ) {
97
+ if let u = e {
98
+ let a : Any = u
99
+ _ = a
100
+ }
101
+ }
102
+ #endif
103
+
68
104
public enum Optional < Wrapped> {
69
105
case none
70
106
case some( Wrapped )
0 commit comments