File: switch_debuginfo.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (100 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download
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
// RUN: %target-swift-emit-silgen -g -Xllvm -sil-print-debuginfo %s | %FileCheck %s

func nop1() {}
func nop2() {}

enum Binary {
  case On
  case Off
}

func isOn(_ b: Binary) -> Bool {
  return b == .On
}

// CHECK: [[LOC:loc "[^"]+"]]

// First, check that we don't assign fresh locations to each case statement,
// except for any relevant debug value instructions.
// CHECK-LABEL: sil hidden [ossa] @$s16switch_debuginfo5test11iySi_tF
func test1(i: Int) {
  switch i {
  case 0:  // CHECK-NOT: [[LOC]]:[[@LINE]]
    nop1()
           
  case 1:  // CHECK-NOT: [[LOC]]:[[@LINE]]
    nop1()

  default: // CHECK-NOT: [[LOC]]:[[@LINE]]
    nop1()
  }
}

// Next, check that case statements and switch subjects have the same locations.
// CHECK-LABEL: sil hidden [ossa] @$s16switch_debuginfo5test21sySS_tF
func test2(s: String) {
  switch s {
  case "a": // CHECK: string_literal utf8 "a", [[LOC]]:[[@LINE-1]]:10
    nop1()
  case "b": // CHECK: string_literal utf8 "b", [[LOC]]:[[@LINE-3]]:10
    nop2()
  default:
    nop1()
  }
}

// Fallthrough shouldn't affect case statement locations.
// CHECK-LABEL: sil hidden [ossa] @$s16switch_debuginfo5test31sySS_tF
func test3(s: String) {
  switch s {
  case "a", "b":
    // CHECK: string_literal utf8 "a", [[LOC]]:[[@LINE-2]]:10
    // CHECK: string_literal utf8 "b", [[LOC]]:[[@LINE-3]]:10
    nop1()
    fallthrough
  case "b", "c":
    // CHECK: string_literal utf8 "b", [[LOC]]:[[@LINE-7]]:10
    // CHECK: string_literal utf8 "c", [[LOC]]:[[@LINE-8]]:10
    nop2()
    fallthrough
  default:
    nop1()
  }
}

// It should be possible to set breakpoints on where clauses.
// CHECK-LABEL: sil hidden [ossa] @$s16switch_debuginfo5test41byAA6BinaryO_tF
func test4(b: Binary) {
  switch b {
  case let _        // CHECK-NOT: [[LOC]]:[[@LINE]]
    where isOn(b):  // CHECK: [[LOC]]:[[@LINE]]:11
    nop1()
  case let _        // CHECK-NOT: [[LOC]]:[[@LINE]]
    where !isOn(b): // CHECK: [[LOC]]:[[@LINE]]:11
    nop2()
  default:
    nop1()
  }
}

// Check that we set the right locations before/after nested switches.
// CHECK-LABEL: sil hidden [ossa] @$s16switch_debuginfo5test51sySS_tF
func test5(s: String) {
  switch s {
  case "a":         // CHECK: string_literal utf8 "a", [[LOC]]:[[@LINE-1]]:10
    switch "b" {
    case "b":       // CHECK: string_literal utf8 "b", [[LOC]]:[[@LINE-1]]:12
      nop1()
    default:
      nop2()
    }
    if "c" == "c" { // CHECK: string_literal utf8 "c", [[LOC]]:[[@LINE]]
      nop1()
    }
  default:
    nop1()
  }
  if "d" == "d" {   // CHECK: string_literal utf8 "d", [[LOC]]:[[@LINE]]
    nop1()
  }
}