Inline assembly: semicolon comments ignored
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
or... not ignored?
I tried this code:
use core::arch::asm;
fn main() {
let mut x: i32 = 0;
unsafe {
asm!(
"mov {0:e}, 1 ; mov {0:e}, 2",
inout(reg) x
);
}
assert_eq!(x, 1);
}
I expected to see this happen: The program exits quietly as mov {0:e}, 2 is a comment.
Instead, this happened: The assertion fails as the comment is evaluated as assembly. Switching the comment delimiter to #, //, or /* ... */ fixes this issue.
This doesn't really pose an issue when writing assembly in a Rust file, as you would (and should) comment it outside of the asm! macro, but if you were to import an otherwise syntactically correct assembly file with global_asm!(include_str!("some_file.asm"), options(raw)) (which is mentioned as being acceptable in the reference) you would get an error if the assembly file had comments.
Meta
rustc --version --verbose:
rustc 1.87.0-nightly (cbfdf0b01 2025-03-13)
binary: rustc
commit-hash: cbfdf0b014cb04982a9cbeec1578001001167f6e
commit-date: 2025-03-13
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Backtrace
thread 'main' panicked at tst/src/main.rs:11:5:
assertion `left == right` failed
left: 2
right: 1
stack backtrace:
0: 0x55e5cfc3e882 - std::backtrace_rs::backtrace::libunwind::trace::h9174a07d358e23da
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
1: 0x55e5cfc3e882 - std::backtrace_rs::backtrace::trace_unsynchronized::h0238535cda48260e
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
2: 0x55e5cfc3e882 - std::sys::backtrace::_print_fmt::h7357ca83600008ca
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/sys/backtrace.rs:66:9
3: 0x55e5cfc3e882 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2ccbb0687a134d3a
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/sys/backtrace.rs:39:26
4: 0x55e5cfc5ba93 - core::fmt::rt::Argument::fmt::h490c80f58cf5cd18
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/fmt/rt.rs:185:76
5: 0x55e5cfc5ba93 - core::fmt::write::hd28d4ac41c011289
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/fmt/mod.rs:1449:21
6: 0x55e5cfc3c463 - std::io::Write::write_fmt::hc802c2c997566d6d
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/io/mod.rs:1890:15
7: 0x55e5cfc3e6d2 - std::sys::backtrace::BacktraceLock::print::h16905c0409b4bd71
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/sys/backtrace.rs:42:9
8: 0x55e5cfc3f5f2 - std::panicking::default_hook::{{closure}}::hd73239ef18e9c626
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:298:22
9: 0x55e5cfc3f3f5 - std::panicking::default_hook::hf79edb81864efc5c
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:325:9
10: 0x55e5cfc3fec2 - std::panicking::rust_panic_with_hook::h8b4624c1a31cf321
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:831:13
11: 0x55e5cfc3fd5a - std::panicking::begin_panic_handler::{{closure}}::he1ef97b10af3d992
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:704:13
12: 0x55e5cfc3ed79 - std::sys::backtrace::__rust_end_short_backtrace::he0d459df86b8ceea
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/sys/backtrace.rs:168:18
13: 0x55e5cfc3f9ed - rust_begin_unwind
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:695:5
14: 0x55e5cfc5af30 - core::panicking::panic_fmt::h3463be8214ef2d7a
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/panicking.rs:75:14
15: 0x55e5cfc5b1b7 - core::panicking::assert_failed_inner::ha0c4af2aad2e05dc
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/panicking.rs:425:17
16: 0x55e5cfc29692 - core::panicking::assert_failed::heb6193dbaff462c9
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/panicking.rs:380:5
17: 0x55e5cfc1fb39 - tst::main::h51f7c8543d6ea0ec
at /home/i/viridian/tst/src/main.rs:11:5
18: 0x55e5cfc1fb8b - core::ops::function::FnOnce::call_once::h154b0b87a9cfab3c
at /home/i/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
19: 0x55e5cfc1fbde - std::sys::backtrace::__rust_begin_short_backtrace::hc3d2ecae4d9e94dd
at /home/i/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
20: 0x55e5cfc1fab1 - std::rt::lang_start::{{closure}}::hdbc8ce7d80b361fd
at /home/i/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:199:18
21: 0x55e5cfc3a450 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h89b9c257652e56a0
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/core/src/ops/function.rs:284:13
22: 0x55e5cfc3a450 - std::panicking::try::do_call::h9154a00e6218a7ee
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:587:40
23: 0x55e5cfc3a450 - std::panicking::try::hc84925c5845b0339
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:550:19
24: 0x55e5cfc3a450 - std::panic::catch_unwind::h62ee428978f0fff1
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panic.rs:359:14
25: 0x55e5cfc3a450 - std::rt::lang_start_internal::{{closure}}::h9cc4a7783ce0ae9b
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/rt.rs:168:24
26: 0x55e5cfc3a450 - std::panicking::try::do_call::hcd34f1f51f4e7728
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:587:40
27: 0x55e5cfc3a450 - std::panicking::try::hbe9440be03c95ae5
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panicking.rs:550:19
28: 0x55e5cfc3a450 - std::panic::catch_unwind::h2730f4191fbd1db1
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/panic.rs:359:14
29: 0x55e5cfc3a450 - std::rt::lang_start_internal::h5544d0e71c42d1c4
at /rustc/cbfdf0b014cb04982a9cbeec1578001001167f6e/library/std/src/rt.rs:164:5
30: 0x55e5cfc1fa97 - std::rt::lang_start::h6412dfef03c3d63c
at /home/i/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:198:5
31: 0x55e5cfc1fb5e - main
32: 0x7fc6226831ca - <unknown>
33: 0x7fc62268328b - __libc_start_main
34: 0x55e5cfc1f995 - _start
35: 0x0 - <unknown>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal asm! reproducer and compare its semicolon behavior with global_asm!(include_str!("some_file.asm"), options(raw)) as described in the issue. The fix is complete when semicolon comments in raw inline assembly are ignored and the example's assertion passes without changing the alternative comment delimiters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100