Skip to content

Commit 1781715

Browse files
authored
constant_vprintf: Add a mode where prints are silenced when -DPRINT_DISABLED is present on the client side (#41177)
1 parent 8533b42 commit 1781715

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/public/core/StaticPrint.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,12 @@ internal func constant_vprintf_backend(
849849
@_semantics("oslog.requires_constant_arguments")
850850
@inlinable
851851
@_transparent
852+
@_alwaysEmitIntoClient
852853
@_optimize(none)
853854
public func constant_vprintf(_ message: ConstantVPrintFMessage) {
854855
let formatString = message.interpolation.formatString
855856
let argumentClosures = message.interpolation.arguments.argumentClosures
857+
if Bool(_builtinBooleanLiteral: Builtin.ifdef_PRINT_DISABLED()) { return }
856858
let formatStringPointer = _getGlobalStringTablePointer(formatString)
857859
constant_vprintf_backend(
858860
fmt: formatStringPointer,

test/stdlib/StaticPrintDisabled.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -I %t -o %t/a1.out -O && %target-run %t/a1.out | %FileCheck %s
3+
// RUN: %target-build-swift %s -D PRINT_DISABLED -I %t -o %t/a2.out -O && %target-run %t/a2.out | %FileCheck %s --check-prefix CHECK-PRINT-DISABLED --allow-empty
4+
5+
// REQUIRES: executable_test
6+
// REQUIRES: stdlib_static_print
7+
8+
let x = 42
9+
let s = "ABCDE"
10+
constant_vprintf("Hello World \(5) \(x) \(s)")
11+
12+
// CHECK: Hello World 5 42 ABCDE
13+
// CHECK-PRINT-DISABLED-NOT: Hello World

0 commit comments

Comments
 (0)