forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
if_expr.swift
48 lines (42 loc) · 1.47 KB
/
if_expr.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// RUN: %target-swift-frontend -emit-silgen %s | FileCheck %s
func fizzbuzz(i: Int) -> String {
return i % 3 == 0
? "fizz"
: i % 5 == 0
? "buzz"
: "\(i)"
// CHECK: cond_br {{%.*}}, [[OUTER_TRUE:bb[0-9]+]], [[OUTER_FALSE:bb[0-9]+]]
// CHECK: [[OUTER_TRUE]]:
// CHECK: br [[OUTER_CONT:bb[0-9]+]]
// CHECK: [[OUTER_FALSE]]:
// CHECK: cond_br {{%.*}}, [[INNER_TRUE:bb[0-9]+]], [[INNER_FALSE:bb[0-9]+]]
// CHECK: [[INNER_TRUE]]:
// CHECK: br [[INNER_CONT:bb[0-9]+]]
// CHECK: [[INNER_FALSE]]:
// CHECK: function_ref {{.*}}stringInterpolation
// CHECK: br [[INNER_CONT]]
// CHECK: [[INNER_CONT]]({{.*}}):
// CHECK: br [[OUTER_CONT]]
// CHECK: [[OUTER_CONT]]({{.*}}):
// CHECK: return
}
protocol AddressOnly {}
struct A : AddressOnly {}
struct B : AddressOnly {}
func consumeAddressOnly(_: AddressOnly) {}
// CHECK: sil hidden @_TF7if_expr19addr_only_ternary_1
func addr_only_ternary_1(x: Bool) -> AddressOnly {
// CHECK: bb0([[RET:%.*]] : $*AddressOnly, {{.*}}):
// CHECK: [[a:%[0-9]+]] = alloc_box $AddressOnly // var a
var a : AddressOnly = A()
// CHECK: [[b:%[0-9]+]] = alloc_box $AddressOnly // var b
var b : AddressOnly = B()
// CHECK: cond_br {{%.*}}, [[TRUE:bb[0-9]+]], [[FALSE:bb[0-9]+]]
// CHECK: [[TRUE]]:
// CHECK: copy_addr [[a]]#1 to [initialization] [[RET]]
// CHECK: br [[CONT:bb[0-9]+]]
// CHECK: [[FALSE]]:
// CHECK: copy_addr [[b]]#1 to [initialization] [[RET]]
// CHECK: br [[CONT]]
return x ? a : b
}