timjrd opened PR #6850 from timjrd:cranelift_validate_iconst_ranges to bytecodealliance:main:
Implements the following checks:
iconst.i8immediate must be within 0 .. 0xFF
iconst.i16immediate must be within 0 .. 0xFFFF
iconst.i32immediate must be within 0 .. 0xFFFFFFFFfix #3059
Explain why this change is needed:
As mentioned in #3059,
iconstcurrently allows any immediate within the range of ani64, even foriconst.i8,iconst.i16oriconst.i32.This breaks some tests!
Running
cargo testin/cranelift/codegenreturns successfully. I also added a few tests concerning the new checks.Running
cargo testin/craneliftreturns some failures. For example:1: - inst1 (v1 = iconst.i8 -1): constant immediate is out of bounds [...] failures: bugpoint::tests::test_reduce run::test::nopWhich is expected if we forbid negative immediates, @jameysharp could you please confirm?
Running
cargo testat the root of this repo returns a lot of failures, possibly related to negative immediates.This is my first contribution so this patch is probably broken.
Last updated: Dec 13 2025 at 19:03 UTC