Zig emits malformed load for struct of two fields in 6th parameter position for C ABI #18916
Labels
arch-x86_64
backend-llvm
The LLVM backend outputs an LLVM IR Module.
bug
Observed behavior contradicts documented or intended behavior
miscompilation
The compiler reports success but produces semantically incorrect code.
Milestone
Zig Version
0.9.0, 0.10.0, 0.11.0, trunk, 0.12.0-dev.2710+c3eb592a3
Steps to Reproduce and Observed Behavior
View this reproduction on Godbolt/Compiler Explorer. It has equivalent code in C (GCC and Clang), Zig, and Rust.
The Zig compiler produces a different load for the
fparameter than the other compilers. I have not checked the spec to confirm, but it seems likely that Zig, being the outlier, is the one emitting the incorrect load.In my testing (positions in the range [1, 8]), it is critical for the
fparameter to be in the 6th position. Any higher or lower and the issue goes away.This issue does not present itself when testing with a
usizeparameter type in either the 6th or 7th parameter positions. Interestingly, from that testing, it looks like Zig might be trying to decomposeFooto its components (usize, usize) and treat each as its own parameter with respect to the ABI:Foo (2 usize fields) as 6th parameter (differs from GCC)
Zig output (you may notice that these loads line up with the loads emitted for a
usize6th and 7th parameter, shown in the other spoilers):GCC output:
Foo (1 usize field) as 6th parameter (same as GCC)
Zig output:
GCC output:
Foo (1 usize field) as 7th parameter (same as GCC)
Zig output:
GCC output:
Expected Behavior
Zig emits a correct load.
If you require more information, or if there is anything I can do to help investigate the cause, I would be happy to help.
The text was updated successfully, but these errors were encountered: