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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
// RUN: %target-swift-emit-silgen -module-name sil_locations -Xllvm -sil-print-debuginfo -emit-verbose-sil %s | %FileCheck %s
// FIXME: Not sure if this an ideal source info for the branch -
// it points to if, not the last instruction in the block.
func ifexpr() -> Int {
var x : Int = 0
if true {
x+=1
}
return x
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations6ifexprSiyF
// CHECK: apply {{.*}}, loc "{{.*}}":[[@LINE-5]]:6
// CHECK: cond_br {{%.*}}, [[TRUE_BB:bb[0-9]+]], [[FALSE_BB:bb[0-9]+]], loc "{{.*}}":[[@LINE-6]]:6
// CHECK: [[TRUE_BB]]:
// CHECK: br [[CONT_BB:bb[0-9]+]], loc "{{.*}}":[[@LINE-6]]:3
// CHECK: [[CONT_BB]]:
// CHECK: return {{.*}}, loc "{{.*}}":[[@LINE-7]]:3, {{.*}}:return
}
func ifelseexpr() -> Int {
var x : Int = 0
if true {
x+=1
} else {
x-=1
}
return x
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations10ifelseexprSiyF
// CHECK: cond_br {{%.*}}, [[TRUE_BB:bb[0-9]+]], [[FALSE_BB:bb[0-9]+]], loc "{{.*}}":[[@LINE-7]]:6
// CHECK: [[TRUE_BB]]:
// CHECK: br bb{{[0-9]+}}, loc "{{.*}}":[[@LINE-7]]:3
// CHECK: [[FALSE_BB]]:
// CHECK: br bb{{[0-9]+}}, loc "{{.*}}":[[@LINE-7]]:3
// CHECK: return {{.*}}, loc "{{.*}}":[[@LINE-7]]:3, {{.*}}:return
}
// The source locations are handled differently here - since
// the return is unified, we keep the location of the return(not the if)
// in the branch.
func ifexpr_return() -> Int {
if true {
return 5
}
return 6
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations13ifexpr_returnSiyF
// CHECK: apply {{.*}}, loc "{{.*}}":[[@LINE-5]]:6
// CHECK: cond_br {{%.*}}, [[TRUE_BB:bb[0-9]+]], [[FALSE_BB:bb[0-9]+]], loc "{{.*}}":[[@LINE-6]]:6
// CHECK: [[TRUE_BB]]:
// CHECK: br bb{{[0-9]+}}({{%.*}}), loc "{{.*}}":[[@LINE-7]]:5, {{.*}}:return
// CHECK: [[FALSE_BB]]:
// CHECK: br bb{{[0-9]+}}({{%.*}}), loc "{{.*}}":[[@LINE-7]]:3, {{.*}}:return
// CHECK: return {{.*}}, loc "{{.*}}":[[@LINE+1]]:1, {{.*}}:cleanup
}
func ifexpr_rval() -> Int {
var x = true ? 5 : 6
return x
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations11ifexpr_rvalSiyF
// CHECK: apply {{.*}}, loc "{{.*}}":[[@LINE-3]]:11
// CHECK: cond_br {{%.*}}, [[TRUE_BB:bb[0-9]+]], [[FALSE_BB:bb[0-9]+]], loc "{{.*}}":[[@LINE-4]]:11
// CHECK: [[TRUE_BB]]:
// CHECK: br bb{{[0-9]+}}({{%.*}}), loc "{{.*}}":[[@LINE-6]]:18
// CHECK: [[FALSE_BB]]:
// CHECK: br bb{{[0-9]+}}({{%.*}}), loc "{{.*}}":[[@LINE-8]]:22
}
// --- Test function calls.
func simpleDirectCallTest(_ i: Int) -> Int {
return simpleDirectCallTest(i)
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations20simpleDirectCallTestyS2iF
// CHECK: function_ref @$s13sil_locations20simpleDirectCallTestyS2iF : {{.*}}, loc "{{.*}}":[[@LINE-2]]:10
// CHECK: {{%.*}} apply {{%.*}} line:[[@LINE-3]]:10
}
func templateTest<T>(_ value: T) -> T {
return value
}
func useTemplateTest() -> Int {
return templateTest(5);
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations15useTemplateTestSiyF
// CHECK: function_ref @$sSi2{{[_0-9a-zA-Z]*}}fC :{{.*}}, loc "{{.*}}":[[@LINE-2]]
}
func foo(_ x: Int) -> Int {
func bar(_ y: Int) -> Int {
return x + y
}
return bar(1)
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations3foo{{[_0-9a-zA-Z]*}}F
// CHECK: [[CLOSURE:%[0-9]+]] = function_ref {{.*}}, loc "{{.*}}":[[@LINE-2]]:10
// CHECK: apply [[CLOSURE:%[0-9]+]]
}
class LocationClass {
func mem() {}
}
func testMethodCall() {
var l: LocationClass
l.mem();
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations14testMethodCallyyF
// CHECK: class_method {{.[0-9]+}} : $LocationClass, #LocationClass.mem : {{.*}}, loc "{{.*}}":[[@LINE-3]]:5
}
func multipleReturnsImplicitAndExplicit() {
var x = 5+3
if x > 10 {
return
}
x += 1
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations34multipleReturnsImplicitAndExplicityyF
// CHECK: cond_br
// CHECK: br bb{{[0-9]+}}, loc "{{.*}}":[[@LINE-5]]:5, {{.*}}:return
// CHECK: br bb{{[0-9]+}}, loc "{{.*}}":[[@LINE+2]]:1, {{.*}}:imp_return
// CHECK: return {{.*}}, loc "{{.*}}":[[@LINE+1]]:1, {{.*}}:cleanup
}
func simplifiedImplicitReturn() -> () {
var y = 0
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations24simplifiedImplicitReturnyyF
// CHECK: return {{.*}}, loc "{{.*}}":[[@LINE+1]]:1, {{.*}}:imp_return
}
func switchfoo() -> Int { return 0 }
func switchbar() -> Int { return 0 }
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations10testSwitchyyF
func testSwitch() {
var x:Int
x = 0
switch (switchfoo(), switchbar()) {
// CHECK: store {{.*}}, loc "{{.*}}":[[@LINE-1]]
case (1,2):
// CHECK: integer_literal $Builtin.IntLiteral, 2, loc "{{.*}}":[[@LINE-3]]:10
// FIXME: Location info is missing.
// CHECK: cond_br
//
var z: Int = 200
// CHECK: [[VAR_Z:%[0-9]+]] = alloc_box ${ var Int }, var, name "z"{{.*}}line:[[@LINE-1]]:9
// CHECK: integer_literal $Builtin.IntLiteral, 200, loc "{{.*}}":[[@LINE-2]]:18
x = z
// CHECK: destroy_value [[VAR_Z]]{{.*}}, loc "{{.*}}":[[@LINE-1]]:9, {{.*}}:cleanup
case (3, let y):
x += 1
default:
()
}
}
func testIf() {
if true {
var y:Int
} else {
var x:Int
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations6testIfyyF
//
// FIXME: Missing location info here.
// CHECK: function_ref
// CHECK: apply
//
//
//
// CHECK: br {{.*}}, loc "{{.*}}":[[@LINE-13]]:6
}
func testFor() {
for i in 0..<10 {
var y: Int = 300
y+=1
if true {
break
}
y-=1
continue
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations7testForyyF
// CHECK: [[VAR_Y_IN_FOR:%[0-9]+]] = alloc_box ${ var Int }, var, name "y", loc "{{.*}}":[[@LINE-10]]:9
// CHECK: integer_literal $Builtin.IntLiteral, 300, loc "{{.*}}":[[@LINE-11]]:18
// CHECK: destroy_value [[VAR_Y_IN_FOR]] : ${ var Int }
// CHECK: br bb{{.*}}, loc "{{.*}}":[[@LINE-10]]:7
// CHECK: destroy_value [[VAR_Y_IN_FOR]] : ${ var Int }
// CHECK: br bb{{.*}}, loc "{{.*}}":[[@LINE-9]]:5
}
func testTuples() {
var t = (2,3)
var tt = (2, (4,5))
var d = "foo"
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations10testTuplesyyF
// CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-4]]:11
// CHECK: integer_literal $Builtin.IntLiteral, 2, loc "{{.*}}":[[@LINE-5]]:12
// CHECK: integer_literal $Builtin.IntLiteral, 3, loc "{{.*}}":[[@LINE-6]]:14
// CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-6]]:12
// CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-7]]:16
}
// Test tuple imploding/exploding.
protocol Ordinable {
func ord() -> Int
}
func b<T : Ordinable>(_ seq: T) -> (Int) -> Int {
return {i in i + seq.ord() }
}
func captures_tuple<T, U>(x: (T, U)) -> () -> (T, U) {
return {x}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations14captures_tuple{{[_0-9a-zA-Z]*}}F
// CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-3]]:27
// CHECK: copy_addr {{.*}}, loc "{{.*}}":[[@LINE-4]]:27
// CHECK: function_ref {{.*}}, loc "{{.*}}":[[@LINE-4]]:10
// CHECK-LABEL: sil private [ossa] @$s13sil_locations14captures_tuple{{.*}}fU_
// CHECK: copy_addr {{.*}}, loc "{{.*}}":[[@LINE-7]]:11
}
func interpolated_string(_ x: Int, y: String) -> String {
return "The \(x) Million Dollar \(y)"
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations19interpolated_string{{[_0-9a-zA-Z]*}}F
// CHECK: function_ref @$ss26DefaultStringInterpolationV15literalCapacity18interpolationCountABSi_SitcfC
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-3]]:10
// CHECK: string_literal utf8 "The ", loc "{{.*}}":[[@LINE-5]]:10
// CHECK: function_ref @$ss26DefaultStringInterpolationV13appendLiteralyySSF
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-7]]:11
// CHECK: store %0 to{{.*}}, loc "{{.*}}":[[@LINE-9]]:17
// CHECK: function_ref @$ss26DefaultStringInterpolationV06appendC0yyxs06CustomB11ConvertibleRzlF
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-11]]:16
// CHECK: string_literal utf8 " Million Dollar ", loc "{{.*}}":[[@LINE-13]]:19
// CHECK: function_ref @$ss26DefaultStringInterpolationV13appendLiteralyySSF
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-15]]:19
// CHECK: store_borrow %1 to {{.*}}, loc "{{.*}}":[[@LINE-17]]:37
// CHECK: function_ref @$ss26DefaultStringInterpolationV06appendC0yyxs06CustomB11ConvertibleRzs20TextOutputStreamableRzlF
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-19]]:36
// CHECK: function_ref @$sSS19stringInterpolationSSs013DefaultStringB0V_tcfC
// CHECK-NEXT: apply{{.*}}, loc "{{.*}}":[[@LINE-22]]:10
}
func int(_ x: Int) {}
func tuple() -> (Int, Float) { return (1, 1.0) }
func tuple_element(_ x: (Int, Float)) {
int(tuple().0)
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations13tuple_element{{[_0-9a-zA-Z]*}}F
// CHECK: apply {{.*}} line:[[@LINE-3]]:7
// CHECK: destructure_tuple {{.*}}line:[[@LINE-4]]:7
// CHECK: apply {{.*}} line:[[@LINE-5]]:3
}
func containers() -> ([Int], Dictionary<String, Int>) {
return ([1, 2, 3], ["Ankeny": 101, "Burnside": 102, "Couch": 103])
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations10containers{{[_0-9a-zA-Z]*}}F
// CHECK: string_literal utf8 "Ankeny", loc "{{.*}}":[[@LINE-3]]:23
// CHECK: integer_literal $Builtin.IntLiteral, 101, loc "{{.*}}":[[@LINE-5]]:33
// CHECK: integer_literal $Builtin.IntLiteral, 102, loc "{{.*}}":[[@LINE-6]]:50
// CHECK: apply {{%.*}}<String, Int>({{%.*}}, {{%.*}}) : {{.*}}, loc "{{.*}}":[[@LINE-8]]:22
}
func a() {}
func b() -> Int { return 0 }
protocol P { func p() }
struct X : P { func p() {} }
func test_isa_2(_ p: P) {
switch (p, b()) {
case (is X, b()):
a()
case _:
a()
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations10test_isa_2{{[_0-9a-zA-Z]*}}F
// CHECK: alloc_stack $(any P, Int), loc "{{.*}}":[[@LINE-10]]:10
// CHECK: tuple_element_addr{{.*}} $*(any P, Int), 0, loc "{{.*}}":[[@LINE-11]]:10
// CHECK: tuple_element_addr{{.*}} $*(any P, Int), 1, loc "{{.*}}":[[@LINE-12]]:10
// CHECK: load {{.*}}, loc "{{.*}}":[[@LINE-12]]:8
//
// CHECK: checked_cast_addr_br {{.*}}, loc "{{.*}}":[[@LINE-14]]:9
// CHECK: load {{.*}}, loc "{{.*}}":[[@LINE-15]]:9
}
func runcibleWhy() {}
protocol Runcible {
func runce()
}
enum SinglePayloadAddressOnly {
case x(Runcible)
case y
}
func printSinglePayloadAddressOnly(_ v:SinglePayloadAddressOnly) {
switch v {
case .x(let runcible):
runcible.runce()
case .y:
runcibleWhy()
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations29printSinglePayloadAddressOnly{{[_0-9a-zA-Z]*}}F
// CHECK: bb0
// CHECK: switch_enum_addr {{.*}} [[FALSE_BB:bb[0-9]+]], {{.*}}line:[[@LINE-10]]:3
// CHECK: [[FALSE_BB]]:
}
func testStringForEachStmt() {
var i = 0
for index in 1..<20 {
i += 1
if i == 15 {
break
}
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations21testStringForEachStmtyyF
// CHECK: br {{.*}} line:[[@LINE-8]]:3
// CHECK: switch_enum {{.*}} line:[[@LINE-9]]:3
// CHECK: cond_br {{.*}} line:[[@LINE-8]]:10
// Break branch:
// CHECK: br {{.*}} line:[[@LINE-9]]:7
// Looping back branch:
// CHECK: br {{.*}} line:[[@LINE-9]]:3
// Condition is false branch:
// CHECK: br {{.*}} line:[[@LINE-16]]:3
}
func testForStmt() {
var m = 0
for i in 0..<10 {
m += 1
if m == 15 {
break
} else {
continue
}
}
}
func testRepeatWhile() {
var m = 0
repeat {
m += 1
} while (m < 200)
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations15testRepeatWhileyyF
// CHECK: br {{.*}} line:[[@LINE-6]]:3
// CHECK: cond_br {{.*}} line:[[@LINE-5]]:14
// Loop back branch:
// CHECK: br {{.*}} line:[[@LINE-7]]:14
}
func testWhile() {
var m = 0
while m < 100 {
m += 1
if m > 5 {
break
}
m += 1
}
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations9testWhileyyF
// CHECK: br {{.*}} line:[[@LINE-9]]:3
// While loop conditional branch:
// CHECK: cond_br {{.*}} line:[[@LINE-11]]:11
// If stmt condition branch:
// CHECK: cond_br {{.*}} line:[[@LINE-11]]:10
// Break branch:
// CHECK: br {{.*}} line:[[@LINE-12]]:7
// Looping back branch:
// CHECK: br {{.*}} line:[[@LINE-11]]:3
}
// Check that the sil location of keypath getter/setter functions is
// marked as autogenerated.
struct Struct {
var structProperty: InnerStruct {
get { InnerStruct() }
set(newStruct) { }
}
struct InnerStruct {}
}
func testKeyPathGetterSetterAutogen() -> Struct.InnerStruct {
let kp = \Struct.structProperty
var s = Struct()
let innerS = Struct.InnerStruct()
s[keyPath: kp] = innerS
return s[keyPath: kp]
// Autogenerated keypath getter
// CHECK-LABEL: sil shared [thunk] [ossa] @$s13sil_locations6StructV14structProperty{{[_0-9a-zA-Z]*}}TK
// CHECK: load {{.*}} loc * "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
// Autogenerated keypath setter
// CHECK-LABEL: sil shared [thunk] [ossa] @$s13sil_locations6StructV14structProperty{{[_0-9a-zA-Z]*}}Tk
// CHECK: load {{.*}} loc * "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
}
|