miri icon indicating copy to clipboard operation
miri copied to clipboard

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

Open saethlin opened this issue 8 months ago • 1 comments

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?

saethlin avatar Jun 19 '24 21:06 saethlin