-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathreturnlocation.swift
177 lines (150 loc) · 5.93 KB
/
returnlocation.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// RUN: %target-build-swift -g -emit-ir %s -o %t.ll
import Foundation
// This file contains linetable testcases for all permutations
// of simple/complex/empty return expressions,
// cleanups/no cleanups, single / multiple return locations.
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_NONE
// CHECK_NONE: define hidden void {{.*}}none
func none(inout a: Int) {
// CHECK_NONE: call void @llvm.dbg{{.*}}, !dbg
// CHECK_NONE: !dbg ![[NONE_INIT:.*]]
a -= 2;
// CHECK_NONE: ret {{.*}}, !dbg ![[NONE_RET:.*]]
// CHECK_NONE: ![[NONE_INIT]] = !MDLocation(line: [[@LINE-2]], column:
// CHECK_NONE: ![[NONE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_EMPTY
// CHECK_EMPTY: define hidden {{.*}}empty
func empty(inout a: Int) {
if a > 24 {
// CHECK-DAG_EMPTY: br {{.*}}, !dbg ![[EMPTY_RET1:.*]]
// CHECK-DAG_EMPTY_RET1: ![[EMPTY_RET1]] = !MDLocation(line: [[@LINE+1]], column: 6,
return
}
a -= 2;
// CHECK-DAG_EMPTY: br {{.*}}, !dbg ![[EMPTY_RET2:.*]]
// CHECK-DAG_EMPTY_RET2: ![[EMPTY_RET]] = !MDLocation(line: [[@LINE+1]], column: 3,
return
// CHECK-DAG_EMPTY: ret {{.*}}, !dbg ![[EMPTY_RET:.*]]
// CHECK-DAG_EMPTY: ![[EMPTY_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_EMPTY_NONE
// CHECK_EMPTY_NONE: define {{.*}}empty_none
func empty_none(inout a: Int) {
if a > 24 {
return;
}
a -= 2;
// CHECK_EMPTY_NONE: ret {{.*}}, !dbg ![[EMPTY_NONE_RET:.*]]
// CHECK_EMPTY_NONE: ![[EMPTY_NONE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_SIMPLE_RET
// CHECK_SIMPLE_RET: define {{.*}}simple
func simple(a: Int) -> Int {
if a > 24 {
return 0;
}
return 1
// CHECK_SIMPLE_RET: ret i{{.*}}, !dbg ![[SIMPLE_RET:.*]]
// CHECK_SIMPLE_RET: ![[SIMPLE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_COMPLEX_RET
// CHECK_COMPLEX_RET: define {{.*}}complex
func complex(a: Int) -> Int {
if a > 24 {
return a*a
}
return a/2
// CHECK_COMPLEX_RET: ret i{{.*}}, !dbg ![[COMPLEX_RET:.*]]
// CHECK_COMPLEX_RET: ![[COMPLEX_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_COMPLEX_SIMPLE
// CHECK_COMPLEX_SIMPLE: define {{.*}}complex_simple
func complex_simple(a: Int) -> Int {
if a > 24 {
return a*a
}
return 2
// CHECK_COMPLEX_SIMPLE: ret i{{.*}}, !dbg ![[COMPLEX_SIMPLE_RET:.*]]
// CHECK_COMPLEX_SIMPLE: ![[COMPLEX_SIMPLE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_SIMPLE_COMPLEX
// CHECK_SIMPLE_COMPLEX: define {{.*}}simple_complex
func simple_complex(a: Int) -> Int {
if a > 24 {
return a*a
}
return 2
// CHECK_SIMPLE_COMPLEX: ret {{.*}}, !dbg ![[SIMPLE_COMPLEX_RET:.*]]
// CHECK_SIMPLE_COMPLEX: ![[SIMPLE_COMPLEX_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// ---------------------------------------------------------------------
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_NONE
// CHECK_CLEANUP_NONE: define {{.*}}cleanup_none
func cleanup_none(inout a: NSString) {
a = "empty"
// CHECK_CLEANUP_NONE: ret void, !dbg ![[CLEANUP_NONE_RET:.*]]
// CHECK_CLEANUP_NONE: ![[CLEANUP_NONE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_EMPTY
// CHECK_CLEANUP_EMPTY: define {{.*}}cleanup_empty
func cleanup_empty(inout a: NSString) {
if a.length > 24 {
return;
}
a = "empty"
return
// CHECK_CLEANUP_EMPTY: ret void, !dbg ![[CLEANUP_EMPTY_RET:.*]]
// CHECK_CLEANUP_EMPTY: ![[CLEANUP_EMPTY_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_EMPTY_NONE
// CHECK_CLEANUP_EMPTY_NONE: define {{.*}}cleanup_empty_none
func cleanup_empty_none(inout a: NSString) {
if a.length > 24 {
return;
}
a = "empty"
// CHECK_CLEANUP_EMPTY_NONE: ret {{.*}}, !dbg ![[CLEANUP_EMPTY_NONE_RET:.*]]
// CHECK_CLEANUP_EMPTY_NONE: ![[CLEANUP_EMPTY_NONE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_SIMPLE_RET
// CHECK_CLEANUP_SIMPLE_RET: define {{.*}}cleanup_simple
func cleanup_simple(a: NSString) -> Int {
if a.length > 24 {
return 0
}
return 1
// CHECK_CLEANUP_SIMPLE_RET: ret {{.*}}, !dbg ![[CLEANUP_SIMPLE_RET:.*]]
// CHECK_CLEANUP_SIMPLE_RET: ![[CLEANUP_SIMPLE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_COMPLEX
// CHECK_CLEANUP_COMPLEX: define {{.*}}cleanup_complex
func cleanup_complex(a: NSString) -> Int {
if a.length > 24 {
return a.length*a.length
}
return a.length/2
// CHECK_CLEANUP_COMPLEX: ret i{{.*}}, !dbg ![[CLEANUP_COMPLEX_RET:.*]]
// CHECK_CLEANUP_COMPLEX: ![[CLEANUP_COMPLEX_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_COMPLEX_SIMPLE
// CHECK_CLEANUP_COMPLEX_SIMPLE: define {{.*}}cleanup_complex_simple
func cleanup_complex_simple(a: NSString) -> Int {
if a.length > 24 {
return a.length*a.length
}
return 2
// CHECK_CLEANUP_COMPLEX_SIMPLE: ret {{.*}}, !dbg ![[CLEANUP_COMPLEX_SIMPLE_RET:.*]]
// CHECK_CLEANUP_COMPLEX_SIMPLE: ![[CLEANUP_COMPLEX_SIMPLE_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// RUN: cat %t.ll | FileCheck %s --check-prefix=CHECK_CLEANUP_SIMPLE_COMPLEX
// CHECK_CLEANUP_SIMPLE_COMPLEX: define {{.*}}cleanup_simple_complex
func cleanup_simple_complex(a: NSString) -> Int {
if a.length > 24 {
return a.length*a.length
}
return 2
// CHECK_CLEANUP_SIMPLE_COMPLEX: ret {{.*}}, !dbg ![[CLEANUP_SIMPLE_COMPLEX_RET:.*]]
// CHECK_CLEANUP_SIMPLE_COMPLEX: ![[CLEANUP_SIMPLE_COMPLEX_RET]] = !MDLocation(line: [[@LINE+1]], column: 1,
}
// ---------------------------------------------------------------------