Inline assembly integer formatter implicitly converts unsigned integer to signed, then sign-extends to power of 2 #21431
Labels
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.14.0-dev.1417+242d268a0
Steps to Reproduce and Observed Behavior
Godbolt link
This code:
Results in this assembly:
What I assume is happening here is described in the title.
32
as au6
is0b100000
, but this gets turned into ani6
, then sign-extended to ani8
. So we end up with0b11100000
, which is224
as au8
.This can be worked around by wrapping
imm
in@as(u8, imm)
:It would be nice if the language did this automatically or if there was a helpful compiler error.
Expected Behavior
The text was updated successfully, but these errors were encountered: