Skip to content

C backend produce incorrect code for inline assembly with input as clobber #23749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
samy-00007 opened this issue May 2, 2025 · 0 comments · May be fixed by #23794
Open

C backend produce incorrect code for inline assembly with input as clobber #23749

samy-00007 opened this issue May 2, 2025 · 0 comments · May be fixed by #23794
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@samy-00007
Copy link
Contributor

Zig Version

0.15.0-dev.442+b9b606969

Steps to Reproduce and Observed Behavior

Zig currently supports having inline assembly inputs as clobbers. However, both clang and gcc do not, so using -ofmt=c produce c code that cannot compile with either.

pub fn main() void {
    const in: usize = 10;
    asm volatile ("" :: [in] "{rax}" (in) : "rax");
}

is valid zig, but produces

// ...
static void main_main__1001(void) {
    /* file:10:2 */
    /* dbg_var_val:in */
    /* file:11:2 */
    register uintptr_t const t0 __asm("rax") = (uintptr_t)10ul;
    __asm volatile("":: [in]"r"(t0): "rax");
    return;
}
// ...

which is not valid c (for gcc and clang anyway).

This make the feature of having inputs as clobbers impossible to use in the std since tests seems to also be run using -ofmt=c.

Expected Behavior

The C backend should produce working c code whenever inline assembly inputs are also in the clobber list.

@samy-00007 samy-00007 added the bug Observed behavior contradicts documented or intended behavior label May 2, 2025
@samy-00007 samy-00007 linked a pull request May 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant