From: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

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>
---
 gcc/rust/expand/rust-macro-builtins-asm.cc |  4 +++-
 gcc/testsuite/rust/compile/issue-4006.rs   | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-4006.rs

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<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 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 }
+}
-- 
2.49.0

Reply via email to