rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.13k stars 318 forks source link

Attempting to allocate with alignment greater than 2^29 ICEs Miri #3687

Open saethlin opened 1 week ago

saethlin commented 1 week ago

This program (reduced from https://crates.io/crates/ialloc)

fn main() {
    let layout = std::alloc::Layout::from_size_align(1, 1 << 30).unwrap();
    unsafe {
        std::alloc::alloc(layout);
    }
}

Will ICE with

thread 'rustc' panicked at src/tools/miri/src/shims/foreign_items.rs:475:50:
called `Result::unwrap()` on an `Err` value: `1073741824` is too large

This limit is deliberate: https://github.com/rust-lang/rust/blob/5c8459f1eceba84dff8d622768dae556ea7c2495/compiler/rustc_abi/src/lib.rs#L699-L700

    // LLVM has a maximal supported alignment of 2^29, we inherit that.
    pub const MAX: Align = Align { pow2: 29 };

We are not LLVM, so I think this limit is simply wrong for Miri. Should we change the struct in the compiler?

RalfJung commented 1 week ago

It doesn't seem unreasonable to have some upper bound on supported alignment, so throw_unsup_format! would also be acceptable IMO.