Skip to content

Commit 1932353

Browse files
LegNeatoFractalFir
andauthored
(bufix) debug_printf macros don't escape '{' and '}' correctly. (#167)
* Fixes a bug with the `debug_printf` and `debug_printfln` macros not escaping '{' and '}' correctly. The `debug_printf` and `debug_printfln` passes its format string to the `asm!` macro, which uses `{` and `}` to separate its arguments. Passing `{` and `}` to `asm!` directly is incorrect, and leads to compilation issues: ``` error: invalid asm template string: expected `'}'`, found `'"'` --> examples/shaders/sky-shader/src/lib.rs:13016:2 | 13015 | unsafe{debug_printf!("Variant3{")}; | -------------------------- in this macro invocation 13016 | unsafe{debug_printf!("fld0:")}; | ----^ expected `'}'` in asm template string | | | because of this opening brace | = note: if you intended to print `{`, you can escape it using `{{` = note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info) ``` This commit escapes those characters using `{{` and `}}`, which removes this issue and produces correct behaviour. * Fix formatting --------- Co-authored-by: FractalFir <[email protected]>
1 parent d3f9af7 commit 1932353

File tree

1 file changed

+4
-0
lines changed
  • crates/spirv-std/macros/src

1 file changed

+4
-0
lines changed

crates/spirv-std/macros/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream {
613613
.into_iter()
614614
.collect::<proc_macro2::TokenStream>();
615615
let op_loads = op_loads.into_iter().collect::<proc_macro2::TokenStream>();
616+
// Escapes the '{' and '}' characters in the format string.
617+
// Since the `asm!` macro expects '{' '}' to surround its arguments, we have to use '{{' and '}}' instead.
618+
// The `asm!` macro will then later turn them back into '{' and '}'.
619+
let format_string = format_string.replace('{', "{{").replace('}', "}}");
616620

617621
let op_string = format!("%string = OpString {format_string:?}");
618622

0 commit comments

Comments
 (0)