CensoredUsername / dynasm-rs

A dynasm-like tool for rust.
https://censoredusername.github.io/dynasm-rs/language/index.html
Mozilla Public License 2.0
716 stars 52 forks source link

Precedence issue when using typemapped operands in x64 mode #95

Closed CensoredUsername closed 5 months ago

CensoredUsername commented 5 months ago
struct Test {
    a: u32,
    b: u32
}

dynasm!(ops
    ; mov rbx => Test[2 + 1].b, rax
);

Generates a displacement of 0x15 instead of 0x1C for some reason.

The code it should generate for the displacement is:

0x1C == (::std::mem::size_of<Test> as i32) * (2 + 1) + offset_of(Test, b).

However it generates 0x15, and the only explanation for that is something like:

0x15 == (::std::mem::size_of<Test> as i32) * 2 + 1 + offset_of(Test, b).

Now this shouldn't be happening, as the code generation for all of this does use delimited groups to avoid this. But it is.

CensoredUsername commented 5 months ago

This is an instance of rust-lang/rust#67062 . Currently rustc does not handle proc_macro::Delimiter::None correctly, leading to issues with interpolated code that uses those due to macro hygiene.

CensoredUsername commented 5 months ago

This annoyingly means delimiting is going to be annoying, as the compiler will warn on unnecessary parenthesis as well. A delimit-if-not-already-delimited function is probably a good idea.