GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Correctly number asm! operands according to GCC expectations.

Fixes incorrect operand numbering in Rust's asm! macro to match GCC's output-then-input order.

This commit rectifies how GCC’s Rust frontend, gccrs, numbers operands within the asm! macro. Previously, operands were numbered based on their appearance order in the macro call, but GCC expects outputs to be numbered before inputs. This mismatch caused incorrect operand references, particularly when inputs preceded outputs, potentially leading to faulty assembly generation. The fix renumbers placeholders to align with GCC’s convention and introduces an error for placeholders appearing after the last defined operand.

In Details

The asm! macro in gccrs previously numbered operands based on their sequence in the macro invocation. However, GCC's inline assembly parser expects operands to be numbered in a specific order: all output operands first, followed by all input operands. This commit modifies expand_inline_asm_strings to correctly renumber the placeholders ({}) according to this convention, resolving issues where input operands incorrectly referred to output operands and vice-versa (as reported in Rust-GCC/gccrs#5057). A new check is also added to reject placeholders that appear beyond the last defined oper…

For Context
asm! macro
A Rust macro that allows embedding assembly language code directly within Rust programs. It provides a way to interact with low-level hardware instructions.
Operand
A value or variable used as input or output for an assembly instruction or macro.
Filed Under: gccrsasminline assemblycompiler backend