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
Reject or correctly widen oversized literals in comparison arithmetic #702
bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
A literal-only arithmetic expression used in a wide comparison is lowered at the default i32 width and then widened. A literal that does not fit i32 is silently truncated, which can turn an upper-bound check into an almost-unbounded check.
Reproduced on Linux amd64 at b71aaf20 (PR #701), at both O0 and O2:
fun main() -> i32 {
var value: u64 = 4294967265;
if (value <= 4294967296 - 32) {
return 1;
}
return 0;
}
The executable returns 1. The generated O0 IR compares against -32 as an unsigned i64:
%cmptmp = icmpulei64%load_value, -32
A typed u64 constant for the bound, or a u64 variable initialized from the same subtraction, preserves 4294967264. The discrepancy was found while implementing WASM allocation bounds; that allocator uses an explicitly typed bound and is not affected by this reproducer.
Please decide and enforce the intended contextual integer arithmetic rule: either evaluate this expression in a permitted wide type or reject an out-of-range default-width literal with a source diagnostic. Silently truncating the literal is not acceptable. Preserve the existing rule that integer division does not become floating division merely because its result is converted to a float.
Acceptance:
Wide comparison bounds containing literal-only arithmetic do not silently truncate oversized literals.
Type checking and codegen agree on arithmetic widths, signedness and conversions.
Regression cases cover comparison operands, grouped arithmetic, calls/returns, signed and unsigned types, and O0/O2.
Existing contextual conversion and integer-division tests remain green.
Related to #681's contextual conversion area, but this is integer operand typing rather than float-to-integer destination signedness. It requires frontend/codegen reasoning and is not labeled good first issue.
bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
Activity
Fix numeric lowering and standard-library boundary handling (wavefnd#707