Skip to content

Commit eac64c3

Browse files
committed
nfc: refactor Backtracing/Crash.swift
This test fused both the CHECK directives and the source code into one file, and is sensitive to the line numbers that source code appears on in that file. Thus, any attempts to add new lines to this test would break it. This refactoring moves the source code to a separate file so its line numbers stay stable.
1 parent e49fd88 commit eac64c3

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

test/Backtracing/Crash.swift renamed to test/Backtracing/Crash.test

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -parse-as-library -Onone -g -o %t/Crash
3-
// RUN: %target-build-swift %s -parse-as-library -Onone -o %t/CrashNoDebug
4-
// RUN: %target-build-swift %s -parse-as-library -O -g -o %t/CrashOpt
5-
// RUN: %target-build-swift %s -parse-as-library -O -o %t/CrashOptNoDebug
2+
// RUN: %target-build-swift %S/Inputs/Crash.swift -parse-as-library -Onone -g -o %t/Crash
3+
// RUN: %target-build-swift %S/Inputs/Crash.swift -parse-as-library -Onone -o %t/CrashNoDebug
4+
// RUN: %target-build-swift %S/Inputs/Crash.swift -parse-as-library -O -g -o %t/CrashOpt
5+
// RUN: %target-build-swift %S/Inputs/Crash.swift -parse-as-library -O -o %t/CrashOptNoDebug
66
// RUN: %target-codesign %t/Crash
77
// RUN: %target-codesign %t/CrashNoDebug
88
// RUN: %target-codesign %t/CrashOpt
@@ -20,45 +20,17 @@
2020
// REQUIRES: backtracing
2121
// REQUIRES: OS=macosx || OS=linux-gnu
2222

23-
func level1() {
24-
level2()
25-
}
26-
27-
func level2() {
28-
level3()
29-
}
30-
31-
func level3() {
32-
level4()
33-
}
34-
35-
func level4() {
36-
level5()
37-
}
38-
39-
func level5() {
40-
print("About to crash")
41-
let ptr = UnsafeMutablePointer<Int>(bitPattern: 4)!
42-
ptr.pointee = 42
43-
}
44-
45-
@main
46-
struct Crash {
47-
static func main() {
48-
level1()
49-
}
50-
}
5123

5224
// CHECK: *** Program crashed: Bad pointer dereference at 0x{{0+}}4 ***
5325

5426
// CHECK: Thread 0 {{(".*" )?}}crashed:
5527

56-
// CHECK: 0 0x{{[0-9a-f]+}} level5() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:42:15
57-
// CHECK-NEXT: 1 [ra] 0x{{[0-9a-f]+}} level4() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:36:3
58-
// CHECK-NEXT: 2 [ra] 0x{{[0-9a-f]+}} level3() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:32:3
59-
// CHECK-NEXT: 3 [ra] 0x{{[0-9a-f]+}} level2() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:28:3
60-
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:24:3
61-
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} static Crash.main() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:48:5
28+
// CHECK: 0 0x{{[0-9a-f]+}} level5() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:19:15
29+
// CHECK-NEXT: 1 [ra] 0x{{[0-9a-f]+}} level4() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:13:3
30+
// CHECK-NEXT: 2 [ra] 0x{{[0-9a-f]+}} level3() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:9:3
31+
// CHECK-NEXT: 3 [ra] 0x{{[0-9a-f]+}} level2() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:5:3
32+
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:1:3
33+
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} static Crash.main() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:25:5
6234
// CHECK-NEXT: 6 [ra] [system] 0x{{[0-9a-f]+}} static Crash.$main() + {{[0-9]+}} in Crash at {{.*}}/<compiler-generated>
6335
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in Crash at {{.*}}/Crash.swift
6436

@@ -72,7 +44,7 @@ struct Crash {
7244

7345
// FRIENDLY: Thread 0 {{(".*" )?}}crashed:
7446

75-
// FRIENDLY: 0 level5() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:42:15
47+
// FRIENDLY: 0 level5() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:19:15
7648

7749
// FRIENDLY: 40| print("About to crash")
7850
// FRIENDLY-NEXT: 41| let ptr = UnsafeMutablePointer<Int>(bitPattern: 4)!
@@ -81,7 +53,7 @@ struct Crash {
8153
// FRIENDLY-NEXT: 43| }
8254
// FRIENDLY-NEXT: 44|
8355

84-
// FRIENDLY: 1 level4() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:36:3
56+
// FRIENDLY: 1 level4() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:13:3
8557

8658
// FRIENDLY: 34|
8759
// FRIENDLY-NEXT: 35| func level4() {
@@ -90,7 +62,7 @@ struct Crash {
9062
// FRIENDLY-NEXT: 37| }
9163
// FRIENDLY-NEXT: 38|
9264

93-
// FRIENDLY: 2 level3() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:32:3
65+
// FRIENDLY: 2 level3() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:9:3
9466

9567
// FRIENDLY: 30|
9668
// FRIENDLY-NEXT: 31| func level3() {
@@ -99,7 +71,7 @@ struct Crash {
9971
// FRIENDLY-NEXT: 33| }
10072
// FRIENDLY-NEXT: 34|
10173

102-
// FRIENDLY: 3 level2() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:28:3
74+
// FRIENDLY: 3 level2() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:5:3
10375

10476
// FRIENDLY: 26|
10577
// FRIENDLY-NEXT: 27| func level2() {
@@ -108,7 +80,7 @@ struct Crash {
10880
// FRIENDLY-NEXT: 29| }
10981
// FRIENDLY-NEXT: 30|
11082

111-
// FRIENDLY: 4 level1() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:24:3
83+
// FRIENDLY: 4 level1() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:1:3
11284

11385
// FRIENDLY: 22|
11486
// FRIENDLY-NEXT: 23| func level1() {
@@ -117,7 +89,7 @@ struct Crash {
11789
// FRIENDLY-NEXT: 25| }
11890
// FRIENDLY-NEXT: 26|
11991

120-
// FRIENDLY: 5 static Crash.main() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:48:5
92+
// FRIENDLY: 5 static Crash.main() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:25:5
12193

12294
// FRIENDLY: 46| struct Crash {
12395
// FRIENDLY-NEXT: 47| static func main() {
@@ -149,12 +121,12 @@ struct Crash {
149121

150122
// OPTIMIZED: Thread 0 {{(".*" )?}}crashed:
151123

152-
// OPTIMIZED: 0 [inlined] 0x{{[0-9a-f]+}} level5() in CrashOpt at {{.*}}/Crash.swift:42:15
153-
// OPTIMIZED-NEXT: 1 [inlined] 0x{{[0-9a-f]+}} level4() in CrashOpt at {{.*}}/Crash.swift:36:3
154-
// OPTIMIZED-NEXT: 2 [inlined] 0x{{[0-9a-f]+}} level3() in CrashOpt at {{.*}}/Crash.swift:32:3
155-
// OPTIMIZED-NEXT: 3 [inlined] 0x{{[0-9a-f]+}} level2() in CrashOpt at {{.*}}/Crash.swift:28:3
156-
// OPTIMIZED-NEXT: 4 [inlined] 0x{{[0-9a-f]+}} level1() in CrashOpt at {{.*}}/Crash.swift:24:3
157-
// OPTIMIZED-NEXT: 5 [inlined] 0x{{[0-9a-f]+}} static Crash.main() in CrashOpt at {{.*}}/Crash.swift:48:5
124+
// OPTIMIZED: 0 [inlined] 0x{{[0-9a-f]+}} level5() in CrashOpt at {{.*}}/Crash.swift:19:15
125+
// OPTIMIZED-NEXT: 1 [inlined] 0x{{[0-9a-f]+}} level4() in CrashOpt at {{.*}}/Crash.swift:13:3
126+
// OPTIMIZED-NEXT: 2 [inlined] 0x{{[0-9a-f]+}} level3() in CrashOpt at {{.*}}/Crash.swift:9:3
127+
// OPTIMIZED-NEXT: 3 [inlined] 0x{{[0-9a-f]+}} level2() in CrashOpt at {{.*}}/Crash.swift:5:3
128+
// OPTIMIZED-NEXT: 4 [inlined] 0x{{[0-9a-f]+}} level1() in CrashOpt at {{.*}}/Crash.swift:1:3
129+
// OPTIMIZED-NEXT: 5 [inlined] 0x{{[0-9a-f]+}} static Crash.main() in CrashOpt at {{.*}}/Crash.swift:25:5
158130
// OPTIMIZED: {{6|7}} [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashOpt at {{.*}}
159131

160132
// OPTIMIZED: Registers:

test/Backtracing/Inputs/Crash.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
func level1() {
2+
level2()
3+
}
4+
5+
func level2() {
6+
level3()
7+
}
8+
9+
func level3() {
10+
level4()
11+
}
12+
13+
func level4() {
14+
level5()
15+
}
16+
17+
func level5() {
18+
print("About to crash")
19+
let ptr = UnsafeMutablePointer<Int>(bitPattern: 4)!
20+
ptr.pointee = 42
21+
}
22+
23+
@main
24+
struct Crash {
25+
static func main() {
26+
level1()
27+
}
28+
}

0 commit comments

Comments
 (0)