You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
t27c gen: strength_reduce turns checked integer x * 2^k into wrapping x << k #6290
module sr;
fn f(x: u8) u8 {
return x * 128;
}
test mul_overflows {
assert(f(3) == 128);
}
t27c gen emits return x << 7;.
t27c test-report reports 1 pass, because 3 * 128 wraps to 128.
With no rewrite, Zig would panic with integer overflow.
t27b (the native backend, checked *) traps integer overflow at line 4 (* on u8).
The reference and t27b therefore disagree on any spec that multiplies by a power of two and overflows. Expected: keep * (or emit std.math.shl with an overflow check) whenever overflow is possible.
Given a t27 spec with a function that multiplies a u8 by 128 (2^7), When t27c gen compiles it, Then the emitted Zig code must use checked multiplication (*) or a checked shift, not an unchecked left shift (<<), so that overflow panics instead of wrapping.
Given the test module from the repro, When running t27c test-report, Then the test must fail (exit non-zero) because the checked multiplication of 3 * 128 overflows u8, matching t27b's trap behavior.
Requirements
FR-001: The strength_reduce / reduce_expr pass in bootstrap/src/compiler.rs MUST NOT rewrite integer x * 2^k into x << k when the multiplication is checked and overflow is possible.
FR-002: For integer types, the compiler MUST preserve checked multiplication semantics (panic on overflow) unless it can prove the operation cannot overflow.
FR-003: If a shift is emitted for multiplication by a power of two, it MUST be a checked shift (e.g., std.math.shl with overflow check) that panics on overflow, matching Zig's * behavior.
Success Criteria
t27c gen on the repro module emits return x * 128; (or a checked shift equivalent) and not return x << 7; — verified by inspecting bootstrap/src/compiler.rs output.
Running t27c test-report on the repro module exits non-zero (test fails due to overflow panic) — the command t27c test-report exits with non-zero.
The existing test suite passes (no regressions) — cargo test in the bootstrap crate exits 0.
Activity
test(t27b fuzz): fixtures from the 1000-case lab run, seed 1791291854 (…
test(t27b fuzz): fixtures from the 1000-case lab run, seed 1791291854 (…
feat(t27b): tri t27b fuzz -- differential fuzzer, generator and judge…