Repository navigation
Description
Problem
Negative and width-or-larger integer shift counts are accepted and lowered directly to LLVM shifts. Executed programs differ between O0 and O2; optimized IR can return poison. The repository needs an explicit Wave contract rather than accidental target behavior.
Starting points: front/parser/src/verification/numeric.rs, llvm/src/codegen/conversions.rs.
Reproduction
Tested at 6257ba3eb4b9f1ab6c247a920c6e0c4b5d699331 on Linux amd64 with LLVM 21.1.8 and a compiler built from that checkout. Build it with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2.
Save as repro.wave:
fun main() -> i32 { var x: i32 = 1; var n: i32 = 32; return x << n; }
target/debug/wavec build repro.wave -O0 --emit=ir,bin --out-dir /tmp/wave-issue-O0
/tmp/wave-issue-O0/repro
target/debug/wavec build repro.wave -O2 --emit=ir,bin --out-dir /tmp/wave-issue-O2
/tmp/wave-issue-O2/reproObserved exit codes: O0=1, O2=40. With n=-1: O0=0, O2=40. Both optimized cases contain ret i32 poison; 40 is an observation, not a stable or promised result.
Scope
Define the valid count range and the treatment of invalid literal and runtime counts. Keep count-range policy separate from mixed-width result typing. Do not prescribe masking, trapping or unchecked behavior without maintainer agreement.
Difficulty: hard.
Completion criteria
- Cover counts 0, width-1, width, negative counts and large unsigned counts.
- Apply the agreed contract consistently in frontend facts and backend lowering.
- Verify constant and runtime expressions at O0/O2, including future backend compatibility.
Design decision needed: Decide the diagnostic, trap, masking or explicitly unchecked policy for out-of-range shifts.
Please mention @LunaStev to discuss the design before starting implementation.
Activity