From: Pierre-Emmanuel Patry Date: Wed, 30 Jul 2025 11:11:52 +0000 (+0200) Subject: gccrs: Fix infinite loop with missing comma X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=697025acf8bedcc59a2e34035ddb6f17a69b8c52;p=thirdparty%2Fgcc.git gccrs: Fix infinite loop with missing comma A missing comma between inline assembly templates did not throw an error and looped indefinitely. gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_format_strings): Emit an error when expecting a comma. gcc/testsuite/ChangeLog: * rust/compile/issue-4006.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index 9dc234cf850..61222dbeacb 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -937,7 +937,9 @@ parse_format_strings (InlineAsmContext inline_asm_ctx) { if (!parser.skip_token (COMMA)) { - break; + rust_error_at (parser.peek_current_token ()->get_locus (), + "expected token %qs", ";"); + return tl::unexpected (COMMITTED); } // Ok after the comma is good, we better be parsing correctly // everything in here, which is formatted string in ABNF diff --git a/gcc/testsuite/rust/compile/issue-4006.rs b/gcc/testsuite/rust/compile/issue-4006.rs new file mode 100644 index 00000000000..328c7b65121 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4006.rs @@ -0,0 +1,13 @@ +#![feature(rustc_attrs)] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} + +pub fn main() { + asm!( + "xor eax, eax" + "xor eax, eax"); + // { dg-error "expected token .;." "" { target *-*-* } .-1 } +}