Skip to content

Commit 7710a97

Browse files
authored
Merge pull request #79698 from kubamracek/embedded-more-traps-stringinterp
[embedded] Allow string-interpolatings in assert, assertionFailure, precondition, preconditionFailure
2 parents 5b4252a + 40aea83 commit 7710a97

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

stdlib/public/core/Assert.swift

-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
/// fails. The default is the line number where `assert(_:_:file:line:)`
3939
/// is called.
4040
@_transparent
41-
@_unavailableInEmbedded
4241
#if $Embedded
4342
@_disfavoredOverload
4443
#endif
@@ -101,7 +100,6 @@ public func assert(
101100
/// fails. The default is the line number where
102101
/// `precondition(_:_:file:line:)` is called.
103102
@_transparent
104-
@_unavailableInEmbedded
105103
#if $Embedded
106104
@_disfavoredOverload
107105
#endif
@@ -167,7 +165,6 @@ public func precondition(
167165
/// line number where `assertionFailure(_:file:line:)` is called.
168166
@inlinable
169167
@inline(__always)
170-
@_unavailableInEmbedded
171168
#if $Embedded
172169
@_disfavoredOverload
173170
#endif
@@ -229,7 +226,6 @@ public func assertionFailure(
229226
/// - line: The line number to print along with `message`. The default is the
230227
/// line number where `preconditionFailure(_:file:line:)` is called.
231228
@_transparent
232-
@_unavailableInEmbedded
233229
#if $Embedded
234230
@_disfavoredOverload
235231
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -emit-ir -Osize -disable-llvm-merge-functions-pass | %FileCheck %s
3+
4+
// REQUIRES: swift_in_compiler
5+
// REQUIRES: optimized_stdlib
6+
// REQUIRES: OS=macosx || OS=linux-gnu
7+
// REQUIRES: swift_feature_Embedded
8+
9+
public func test1(i: Int) {
10+
fatalError("\(i) is not 42")
11+
}
12+
13+
public func test2(i: Int) {
14+
assert(i == 42, "\(i) is not 42")
15+
}
16+
17+
public func test3(i: Int) {
18+
precondition(i == 42, "\(i) is not 42")
19+
}
20+
21+
public func test4(i: Int) {
22+
assertionFailure("\(i) is not 42")
23+
}
24+
25+
public func test5(i: Int) {
26+
preconditionFailure("\(i) is not 42")
27+
}
28+
29+
// CHECK: define {{.*}}@"$e4main5test11iySi_tF"
30+
// CHECK-NEXT: entry:
31+
// CHECK-NEXT: tail call void asm sideeffect ""
32+
// CHECK-NEXT: tail call void @llvm.trap()
33+
// CHECK-NEXT: unreachable
34+
// CHECK-NEXT: }
35+
36+
// CHECK: define {{.*}}@"$e4main5test21iySi_tF"
37+
// CHECK-NEXT: entry:
38+
// CHECK-NEXT: ret void
39+
// CHECK-NEXT: }
40+
41+
// CHECK: define {{.*}}@"$e4main5test31iySi_tF"
42+
// CHECK-NEXT: entry:
43+
// CHECK-NEXT: %.not = icmp eq i64 %0, 42
44+
// CHECK-NEXT: br i1 %.not, label %1, label %2
45+
// CHECK-EMPTY:
46+
// CHECK-NEXT: 1:
47+
// CHECK-NEXT: ret void
48+
// CHECK-EMPTY:
49+
// CHECK-NEXT: 2:
50+
// CHECK-NEXT: tail call void asm sideeffect ""
51+
// CHECK-NEXT: tail call void @llvm.trap()
52+
// CHECK-NEXT: unreachable
53+
// CHECK-NEXT: }
54+
55+
// CHECK: define {{.*}}@"$e4main5test41iySi_tF"
56+
// CHECK-NEXT: entry:
57+
// CHECK-NEXT: ret void
58+
// CHECK-NEXT: }
59+
60+
// CHECK: define {{.*}}@"$e4main5test51iySi_tF"
61+
// CHECK-NEXT: entry:
62+
// CHECK-NEXT: tail call void asm sideeffect ""
63+
// CHECK-NEXT: tail call void @llvm.trap()
64+
// CHECK-NEXT: unreachable
65+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)