Skip to content

[embedded] Allow string-interpolatings in assert, assertionFailure, precondition, preconditionFailure #79698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions stdlib/public/core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
/// fails. The default is the line number where `assert(_:_:file:line:)`
/// is called.
@_transparent
@_unavailableInEmbedded
#if $Embedded
@_disfavoredOverload
#endif
Expand Down Expand Up @@ -101,7 +100,6 @@ public func assert(
/// fails. The default is the line number where
/// `precondition(_:_:file:line:)` is called.
@_transparent
@_unavailableInEmbedded
#if $Embedded
@_disfavoredOverload
#endif
Expand Down Expand Up @@ -167,7 +165,6 @@ public func precondition(
/// line number where `assertionFailure(_:file:line:)` is called.
@inlinable
@inline(__always)
@_unavailableInEmbedded
#if $Embedded
@_disfavoredOverload
#endif
Expand Down Expand Up @@ -229,7 +226,6 @@ public func assertionFailure(
/// - line: The line number to print along with `message`. The default is the
/// line number where `preconditionFailure(_:file:line:)` is called.
@_transparent
@_unavailableInEmbedded
#if $Embedded
@_disfavoredOverload
#endif
Expand Down
65 changes: 65 additions & 0 deletions test/embedded/traps-string-interpolations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -emit-ir -Osize -disable-llvm-merge-functions-pass | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: OS=macosx || OS=linux-gnu
// REQUIRES: swift_feature_Embedded

public func test1(i: Int) {
fatalError("\(i) is not 42")
}

public func test2(i: Int) {
assert(i == 42, "\(i) is not 42")
}

public func test3(i: Int) {
precondition(i == 42, "\(i) is not 42")
}

public func test4(i: Int) {
assertionFailure("\(i) is not 42")
}

public func test5(i: Int) {
preconditionFailure("\(i) is not 42")
}

// CHECK: define {{.*}}@"$e4main5test11iySi_tF"
// CHECK-NEXT: entry:
// CHECK-NEXT: tail call void asm sideeffect ""
// CHECK-NEXT: tail call void @llvm.trap()
// CHECK-NEXT: unreachable
// CHECK-NEXT: }

// CHECK: define {{.*}}@"$e4main5test21iySi_tF"
// CHECK-NEXT: entry:
// CHECK-NEXT: ret void
// CHECK-NEXT: }

// CHECK: define {{.*}}@"$e4main5test31iySi_tF"
// CHECK-NEXT: entry:
// CHECK-NEXT: %.not = icmp eq i64 %0, 42
// CHECK-NEXT: br i1 %.not, label %1, label %2
// CHECK-EMPTY:
// CHECK-NEXT: 1:
// CHECK-NEXT: ret void
// CHECK-EMPTY:
// CHECK-NEXT: 2:
// CHECK-NEXT: tail call void asm sideeffect ""
// CHECK-NEXT: tail call void @llvm.trap()
// CHECK-NEXT: unreachable
// CHECK-NEXT: }

// CHECK: define {{.*}}@"$e4main5test41iySi_tF"
// CHECK-NEXT: entry:
// CHECK-NEXT: ret void
// CHECK-NEXT: }

// CHECK: define {{.*}}@"$e4main5test51iySi_tF"
// CHECK-NEXT: entry:
// CHECK-NEXT: tail call void asm sideeffect ""
// CHECK-NEXT: tail call void @llvm.trap()
// CHECK-NEXT: unreachable
// CHECK-NEXT: }