Skip to content

Commit e0c83de

Browse files
committed
[embedded] Add IR tests for fatalError and precondition in embedded Swift
1 parent 8b22534 commit e0c83de

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo %s | %FileCheck %s --check-prefix=CHECK-MESSAGE
2+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo %s -O | %FileCheck %s --check-prefix=CHECK-NOMESSAGE
3+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo %s -Osize | %FileCheck %s --check-prefix=CHECK-NOMESSAGE
4+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo %s -O -assert-config Debug | %FileCheck %s --check-prefix=CHECK-MESSAGE
5+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo %s -Osize -assert-config Debug | %FileCheck %s --check-prefix=CHECK-MESSAGE
6+
7+
// REQUIRES: swift_in_compiler
8+
// REQUIRES: optimized_stdlib
9+
// REQUIRES: OS=macosx || OS=linux-gnu
10+
11+
public func test() {
12+
fatalError("task failed successfully")
13+
}
14+
15+
// CHECK-MESSAGE: define {{.*}}void @"$s4main4testyyF"(){{.*}} {
16+
// CHECK-MESSAGE: entry:
17+
// CHECK-MESSAGE: {{.*}}call {{.*}}void @"$ss17_assertionFailure__
18+
// CHECK-MESSAGE-SAME: Fatal error
19+
// CHECK-MESSAGE-SAME: task failed successfully
20+
// CHECK-MESSAGE-SAME: traps-fatalerror-ir.swift
21+
// CHECK-MESSAGE: unreachable
22+
// CHECK-MESSAGE: }
23+
24+
// CHECK-NOMESSAGE: define {{.*}}void @"$s4main4testyyF"(){{.*}} {
25+
// CHECK-NOMESSAGE-NEXT: entry:
26+
// CHECK-NOMESSAGE-NEXT: unreachable
27+
// CHECK-NOMESSAGE-NEXT: }
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo -Xllvm -link-embedded-runtime=0 %s -O | %FileCheck %s --check-prefix=CHECK-NOMESSAGE
2+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo -Xllvm -link-embedded-runtime=0 %s -Osize | %FileCheck %s --check-prefix=CHECK-NOMESSAGE
3+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo -Xllvm -link-embedded-runtime=0 %s -O -assert-config Debug | %FileCheck %s --check-prefix=CHECK-MESSAGE
4+
// RUN: %target-swift-emit-ir -enable-experimental-feature Embedded -wmo -Xllvm -link-embedded-runtime=0 %s -Osize -assert-config Debug | %FileCheck %s --check-prefix=CHECK-MESSAGE
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: optimized_stdlib
8+
// REQUIRES: OS=macosx || OS=linux-gnu
9+
10+
@_extern(c)
11+
public func external()
12+
13+
public func test(i: Int) {
14+
precondition(i % 2 == 0, "precondition 1")
15+
external()
16+
precondition(i % 3 == 0, "precondition 3")
17+
external()
18+
precondition(i % 5 == 0, "precondition 5")
19+
external()
20+
precondition(i % 7 == 0, "precondition 7")
21+
}
22+
23+
// "Non-production builds" - We expect 4 separate _assertionFailure() calls with different values
24+
// CHECK-MESSAGE: define {{.*}}void @"$s4main4test1iySi_tF"(i64 %0) {{.*}}{
25+
// CHECK-MESSAGE: call {{.*}}@"$ss17_assertionFailure
26+
// CHECK-MESSAGE: unreachable
27+
// CHECK-MESSAGE: call {{.*}}@"$ss17_assertionFailure
28+
// CHECK-MESSAGE: unreachable
29+
// CHECK-MESSAGE: call {{.*}}@"$ss17_assertionFailure
30+
// CHECK-MESSAGE: unreachable
31+
// CHECK-MESSAGE: call {{.*}}@"$ss17_assertionFailure
32+
// CHECK-MESSAGE: unreachable
33+
// CHECK-MESSAGE: }
34+
35+
// "Production builds" - We expect 4 separate trap blocks in the IR.
36+
// CHECK-NOMESSAGE: define {{.*}}void @"$s4main4test1iySi_tF"(i64 %0) {{.*}}{
37+
// CHECK-NOMESSAGE: tail call void asm sideeffect "", "n"(i32 0) #3
38+
// CHECK-NOMESSAGE: tail call void @llvm.trap()
39+
// CHECK-NOMESSAGE: unreachable
40+
// CHECK-NOMESSAGE: tail call void asm sideeffect "", "n"(i32 1) #3
41+
// CHECK-NOMESSAGE: tail call void @llvm.trap()
42+
// CHECK-NOMESSAGE: unreachable
43+
// CHECK-NOMESSAGE: tail call void asm sideeffect "", "n"(i32 2) #3
44+
// CHECK-NOMESSAGE: tail call void @llvm.trap()
45+
// CHECK-NOMESSAGE: unreachable
46+
// CHECK-NOMESSAGE: tail call void asm sideeffect "", "n"(i32 3) #3
47+
// CHECK-NOMESSAGE: tail call void @llvm.trap()
48+
// CHECK-NOMESSAGE: unreachable
49+
// CHECK-NOMESSAGE: }

0 commit comments

Comments
 (0)