https://gcc.gnu.org/g:697025acf8bedcc59a2e34035ddb6f17a69b8c52

commit r16-2968-g697025acf8bedcc59a2e34035ddb6f17a69b8c52
Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
Date:   Wed Jul 30 13:11:52 2025 +0200

    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 <pierre-emmanuel.pa...@embecosm.com>

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc |  4 +++-
 gcc/testsuite/rust/compile/issue-4006.rs   | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 9dc234cf850c..61222dbeacb2 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<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
index 000000000000..328c7b651214
--- /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 }
+}

Reply via email to