zig icon indicating copy to clipboard operation
zig copied to clipboard

Inline asm *m operands reference stack with self-hosted compiler

Open lluchs opened this issue 3 years ago • 0 comments

Zig Version

0.11.0-dev.86+b83e4d965

Steps to Reproduce and Observed Behavior

Example on godbolt: https://godbolt.org/z/v9nGn98Wh

export fn asm_memory(mem: *u8) void {
    asm volatile ("vmovntdq %%ymm0, %[addr]"
        :                                   
        : [addr] "*m" (mem),            
        : "memory"                          
    );                                      
}

The stage1 compiler puts the address to mem in rax and compiles the instruction to:

vmovntdq %ymm0,(%rax)

The self-hosted compiler puts the address on the stack and compiles the instruction to

vmovntdq %ymm0,-0x18(%rbp)

... so the instruction now writes to the stack instead of mem.

Expected Behavior

Same output from stage1 and self-hosted compiler.

#10367 might be related, but that case was apparently already broken in stage1.

lluchs avatar Nov 07 '22 15:11 lluchs