]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix infinite loop with missing comma
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 30 Jul 2025 11:11:52 +0000 (13:11 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:59 +0000 (16:36 +0200)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/expand/rust-macro-builtins-asm.cc
gcc/testsuite/rust/compile/issue-4006.rs [new file with mode: 0644]

index 9dc234cf850c44bc4db528b1d158bfbe2b4898ae..61222dbeacb2b02bcb31391c97296a15117c733a 100644 (file)
@@ -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<InlineAsmParseError> (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 (file)
index 0000000..328c7b6
--- /dev/null
@@ -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 }
+}