Skip to content

Compilation failure with cranelift due to simd intrinsics #1615

@theoparis

Description

@theoparis
thread 'rustc' (97775) panicked at /rustc-dev/4f14395c37db4c1be874e6b0ace6721674223c22/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs:1009:29:
index out of bounds: the len is 3 but the index is 3

This codebase compiles fine with llvm, but fails with cranelift.

Full compile error
thread 'rustc' (97775) panicked at /rustc-dev/4f14395c37db4c1be874e6b0ace6721674223c22/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs:1009:29:
index out of bounds: the len is 3 but the index is 3
stack backtrace:
   0:     0x7ffff4c1b853 - <<std[1e8bc1f935b91b92]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[cd8074c71add9792]::fmt::Display>::fmt
   1:     0x7ffff5210648 - core[cd8074c71add9792]::fmt::write
   2:     0x7ffff4c31fa6 - <std[1e8bc1f935b91b92]::sys::stdio::unix::Stderr as std[1e8bc1f935b91b92]::io::Write>::write_fmt
   3:     0x7ffff4bf1ff8 - std[1e8bc1f935b91b92]::panicking::default_hook::{closure#0}
   4:     0x7ffff4c0f6c3 - std[1e8bc1f935b91b92]::panicking::default_hook
   5:     0x7ffff3bff487 - std[1e8bc1f935b91b92]::panicking::update_hook::<alloc[cd5d7e5e2db93604]::boxed::Box<rustc_driver_impl[c459b3cab2ad352e]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ffff4c0f9a2 - std[1e8bc1f935b91b92]::panicking::panic_with_hook
   7:     0x7ffff4bf20b8 - std[1e8bc1f935b91b92]::panicking::panic_handler::{closure#0}
   8:     0x7ffff4be68b9 - std[1e8bc1f935b91b92]::sys::backtrace::__rust_end_short_backtrace::<std[1e8bc1f935b91b92]::panicking::panic_handler::{closure#0}, !>
   9:     0x7ffff4bf3bad - __rustc[ef8d9c2cf4986a62]::rust_begin_unwind
  10:     0x7ffff1f5ac3c - core[cd8074c71add9792]::panicking::panic_fmt
  11:     0x7ffff1cd35c3 - core[cd8074c71add9792]::panicking::panic_bounds_check
  12:     0x7fffe2ccbaa1 - rustc_codegen_cranelift[9dacc423fe09fcf6]::intrinsics::simd::codegen_simd_intrinsic_call
  13:     0x7fffe2ca64d2 - rustc_codegen_cranelift[9dacc423fe09fcf6]::abi::codegen_terminator_call
  14:     0x7fffe2cb8849 - rustc_codegen_cranelift[9dacc423fe09fcf6]::base::codegen_fn_body
  15:     0x7fffe2cddcad - rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::codegen_cgu_content
  16:     0x7fffe2cd8d25 - rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::module_codegen
  17:     0x7fffe2c6e590 - <rustc_middle[6b76d97bdc9ea9d4]::dep_graph::DepsType as rustc_query_system[f018106ef91b940e]::dep_graph::Deps>::with_deps::<<rustc_query_system[f018106ef91b940e]::dep_graph::graph::DepGraphData<rustc_middle[6b76d97bdc9ea9d4]::dep_graph::DepsType>>::with_task<rustc_middle[6b76d97bdc9ea9d4]::ty::context::TyCtxt, (alloc[cd5d7e5e2db93604]::sync::Arc<rustc_codegen_cranelift[9dacc423fe09fcf6]::global_asm::GlobalAsmConfig>, rustc_span[935017625644c213]::symbol::Symbol, rustc_codegen_cranelift[9dacc423fe09fcf6]::concurrency_limiter::ConcurrencyLimiterToken), rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::OngoingModuleCodegen>::{closure#1}::{closure#0}, rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::OngoingModuleCodegen>
  18:     0x7fffe2c7717d - rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::run_aot::{closure#3}::{closure#0}
  19:     0x7fffe2ceaf59 - <core[cd8074c71add9792]::iter::adapters::filter_map::FilterMap<alloc[cd5d7e5e2db93604]::vec::into_iter::IntoIter<(usize, &rustc_middle[6b76d97bdc9ea9d4]::mir::mono::CodegenUnit)>, rustc_data_structures[ebf68236c9779ec0]::sync::parallel::par_map<(usize, &rustc_middle[6b76d97bdc9ea9d4]::mir::mono::CodegenUnit), alloc[cd5d7e5e2db93604]::vec::Vec<(usize, &rustc_middle[6b76d97bdc9ea9d4]::mir::mono::CodegenUnit)>, rustc_data_structures[ebf68236c9779ec0]::marker::IntoDynSyncSend<rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::OngoingModuleCodegen>, alloc[cd5d7e5e2db93604]::vec::Vec<rustc_data_structures[ebf68236c9779ec0]::marker::IntoDynSyncSend<rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::OngoingModuleCodegen>>, rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#3}> as core[cd8074c71add9792]::iter::traits::iterator::Iterator>::next
  20:     0x7fffe2ce2750 - rustc_codegen_cranelift[9dacc423fe09fcf6]::driver::aot::run_aot
  21:     0x7fffe2cf6805 - <rustc_codegen_cranelift[9dacc423fe09fcf6]::CraneliftCodegenBackend as rustc_codegen_ssa[b037e73da520fc85]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x7ffff658fc55 - <rustc_interface[97aff6906ce0619f]::queries::Linker>::codegen_and_build_linker
  23:     0x7ffff658c799 - <rustc_interface[97aff6906ce0619f]::passes::create_and_enter_global_ctxt<core[cd8074c71add9792]::option::Option<rustc_interface[97aff6906ce0619f]::queries::Linker>, rustc_driver_impl[c459b3cab2ad352e]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[cd8074c71add9792]::ops::function::FnOnce<(&rustc_session[ff7ca5f6293e7cb7]::session::Session, rustc_middle[6b76d97bdc9ea9d4]::ty::context::CurrentGcx, alloc[cd5d7e5e2db93604]::sync::Arc<rustc_data_structures[ebf68236c9779ec0]::jobserver::Proxy>, &std[1e8bc1f935b91b92]::sync::once_lock::OnceLock<rustc_middle[6b76d97bdc9ea9d4]::ty::context::GlobalCtxt>, &rustc_data_structures[ebf68236c9779ec0]::sync::worker_local::WorkerLocal<rustc_middle[6b76d97bdc9ea9d4]::arena::Arena>, &rustc_data_structures[ebf68236c9779ec0]::sync::worker_local::WorkerLocal<rustc_hir[6ef0f9647e0964a1]::Arena>, rustc_driver_impl[c459b3cab2ad352e]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  24:     0x7ffff63990fc - rustc_interface[97aff6906ce0619f]::interface::run_compiler::<(), rustc_driver_impl[c459b3cab2ad352e]::run_compiler::{closure#0}>::{closure#1}
  25:     0x7ffff6377bce - std[1e8bc1f935b91b92]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[97aff6906ce0619f]::util::run_in_thread_with_globals<rustc_interface[97aff6906ce0619f]::util::run_in_thread_pool_with_globals<rustc_interface[97aff6906ce0619f]::interface::run_compiler<(), rustc_driver_impl[c459b3cab2ad352e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x7ffff63779a0 - <std[1e8bc1f935b91b92]::thread::lifecycle::spawn_unchecked<rustc_interface[97aff6906ce0619f]::util::run_in_thread_with_globals<rustc_interface[97aff6906ce0619f]::util::run_in_thread_pool_with_globals<rustc_interface[97aff6906ce0619f]::interface::run_compiler<(), rustc_driver_impl[c459b3cab2ad352e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[cd8074c71add9792]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7ffff637c9b8 - <std[1e8bc1f935b91b92]::sys::thread::unix::Thread>::new::thread_start
  28:     0x7fffefc9a97a - start_thread
  29:     0x7fffefd22d2c - __GI___clone3
  30:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/theo/src/vibecraft/rustc-ice-2025-12-24T00_21_35-97773.txt` to your bug report

note: compiler flags: --crate-type bin -C opt-level=1 -C embed-bitcode=no -Z codegen-backend=cranelift -C debuginfo=2 -C debug-assertions=on -C linker=clang -C incremental=[REDACTED] -C link-arg=--ld-path=wild

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
terminator _0 = simd_gather::<Simd<T, N>, Simd<*const T, N>, Simd<isize, N>>(move _4, move _17, move _14) -> [return: bb10, unwind unreachable]
fn std::simd::Simd::<T, N>::gather_select(_1: &[T], _2: std::simd::Mask<isize, N>, _3: std::simd::Simd<usize, N>, _4: std::simd::Simd<T, N>) -> std::simd::Simd<T, N> {
    debug slice => _1;
    debug enable => _2;
    debug idxs => _3;
    debug or => _4;
    let mut _0: std::simd::Simd<T, N>;
    let mut _5: std::simd::Simd<usize, N>;
    let mut _6: usize;
    let mut _20: std::simd::Simd<isize, N>;
    scope 1 {
        debug (((enable: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _14;
        scope 14 (inlined std::simd::Simd::<T, N>::gather_select_unchecked) {
            debug slice => _1;
            debug (((enable: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _14;
            debug idxs => _3;
            debug or => _4;
            let _15: std::simd::Simd<*const T, N>;
            let mut _16: *const T;
            scope 15 {
                debug base_ptr => _15;
                let _17: std::simd::Simd<*const T, N>;
                scope 16 {
                    debug ptrs => _17;
                    scope 22 (inlined std::simd::Simd::<T, N>::gather_select_ptr) {
                        debug source => _17;
                        debug (((enable: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _14;
                        debug or => _4;
                        scope 23 (inlined std::simd::Mask::<isize, N>::to_int) {
                            debug (((self: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _14;
                            scope 24 (inlined core::core_simd::masks::mask_impl::Mask::<isize, N>::to_int) {
                            }
                        }
                    }
                }
                scope 19 (inlined <std::simd::Simd<*const T, N> as std::simd::ptr::SimdConstPtr>::wrapping_add) {
                    debug self => _15;
                    debug count => _3;
                    let mut _19: std::simd::Simd<isize, N>;
                    scope 20 (inlined <std::simd::Simd<usize, N> as std::simd::num::SimdUint>::cast::<isize>) {
                        debug self => _3;
                    }
                    scope 21 (inlined <std::simd::Simd<*const T, N> as std::simd::ptr::SimdConstPtr>::wrapping_offset) {
                        debug self => _15;
                        debug count => _19;
                    }
                }
            }
            scope 17 (inlined core::slice::<impl [T]>::as_ptr) {
                debug self => _1;
                let mut _18: *const [T];
            }
            scope 18 (inlined std::simd::Simd::<*const T, N>::splat) {
                debug value => _16;
            }
        }
    }
    scope 2 (inlined std::simd::Simd::<usize, N>::splat) {
        debug value => _6;
    }
    scope 3 (inlined <std::simd::Simd<usize, N> as std::simd::cmp::SimdPartialOrd>::simd_lt) {
        debug self => _3;
        debug other => _5;
        let mut _7: std::simd::Simd<isize, N>;
        scope 4 (inlined std::simd::Mask::<isize, N>::from_int_unchecked) {
            debug value => _7;
            let mut _8: bool;
            scope 5 (inlined core::core_simd::masks::mask_impl::Mask::<isize, N>::from_int_unchecked) {
                debug value => _7;
            }
            scope 6 (inlined core::core_simd::masks::<impl core::core_simd::masks::sealed::Sealed for isize>::valid::<N>) {
                debug value => _7;
                let _9: std::simd::Simd<isize, N>;
                let mut _10: std::simd::Simd<isize, N>;
                let mut _12: std::simd::Simd<isize, N>;
                scope 7 {
                    debug falses => _9;
                    let _11: std::simd::Simd<isize, N>;
                    scope 8 {
                        debug trues => _11;
                        let _13: std::simd::Simd<isize, N>;
                        scope 9 {
                            debug valid => _13;
                        }
                    }
                    scope 11 (inlined std::simd::Simd::<isize, N>::splat) {
                        debug value => const -1_isize;
                    }
                }
                scope 10 (inlined std::simd::Simd::<isize, N>::splat) {
                    debug value => const 0_isize;
                }
            }
        }
    }
    scope 12 (inlined <std::simd::Mask<isize, N> as std::ops::BitAnd>::bitand) {
        debug (((self: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _20;
        debug (((rhs: std::simd::Mask<isize, N>).0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _7;
        scope 13 (inlined <core::core_simd::masks::mask_impl::Mask<isize, N> as std::ops::BitAnd>::bitand) {
            debug ((self: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _20;
            debug ((rhs: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>) => _7;
            let mut _14: std::simd::Simd<isize, N>;
        }
    }

    bb0: {
        _20 = copy ((_2.0: core::core_simd::masks::mask_impl::Mask<isize, N>).0: std::simd::Simd<isize, N>);
        StorageLive(_5);
        StorageLive(_6);
        _6 = PtrMetadata(copy _1);
        _5 = std::simd::Simd::<T, N>::splat::splat_rt::<usize, N>(move _6) -> [return: bb1, unwind continue];
    }

    bb1: {
        StorageDead(_6);
        _7 = std::intrinsics::simd::simd_lt::<std::simd::Simd<usize, N>, std::simd::Simd<isize, N>>(copy _3, move _5) -> [return: bb2, unwind unreachable];
    }

    bb2: {
        StorageLive(_8);
        StorageLive(_9);
        StorageLive(_11);
        StorageLive(_13);
        StorageLive(_10);
        _10 = std::simd::Simd::<T, N>::splat::splat_rt::<isize, N>(const 0_isize) -> [return: bb7, unwind continue];
    }

    bb3: {
        StorageDead(_13);
        StorageDead(_11);
        StorageDead(_9);
        assume(move _8);
        StorageDead(_8);
        StorageDead(_5);
        _14 = std::intrinsics::simd::simd_and::<std::simd::Simd<isize, N>>(move _20, move _7) -> [return: bb9, unwind unreachable];
    }

    bb4: {
        StorageDead(_10);
        StorageLive(_12);
        _12 = std::simd::Simd::<T, N>::splat::splat_rt::<isize, N>(const -1_isize) -> [return: bb8, unwind continue];
    }

    bb5: {
        StorageDead(_12);
        _13 = std::intrinsics::simd::simd_or::<std::simd::Simd<isize, N>>(move _9, move _11) -> [return: bb6, unwind unreachable];
    }

    bb6: {
        _8 = std::intrinsics::simd::simd_reduce_all::<std::simd::Simd<isize, N>>(move _13) -> [return: bb3, unwind unreachable];
    }

    bb7: {
        _9 = std::intrinsics::simd::simd_eq::<std::simd::Simd<isize, N>, std::simd::Simd<isize, N>>(copy _7, move _10) -> [return: bb4, unwind unreachable];
    }

    bb8: {
        _11 = std::intrinsics::simd::simd_eq::<std::simd::Simd<isize, N>, std::simd::Simd<isize, N>>(copy _7, move _12) -> [return: bb5, unwind unreachable];
    }

    bb9: {
        StorageLive(_15);
        StorageLive(_17);
        StorageLive(_16);
        StorageLive(_18);
        _18 = &raw const (*_1);
        _16 = copy _18 as *const T (PtrToPtr);
        StorageDead(_18);
        _15 = std::simd::Simd::<T, N>::splat::splat_rt::<*const T, N>(move _16) -> [return: bb11, unwind continue];
    }

    bb10: {
        StorageDead(_17);
        StorageDead(_15);
        return;
    }

    bb11: {
        StorageDead(_16);
        StorageLive(_19);
        _19 = std::intrinsics::simd::simd_as::<std::simd::Simd<usize, N>, std::simd::Simd<isize, N>>(move _3) -> [return: bb12, unwind unreachable];
    }

    bb12: {
        _17 = std::intrinsics::simd::simd_arith_offset::<std::simd::Simd<*const T, N>, std::simd::Simd<isize, N>>(move _15, move _19) -> [return: bb13, unwind unreachable];
    }

    bb13: {
        StorageDead(_19);
        _0 = std::intrinsics::simd::simd_gather::<std::simd::Simd<T, N>, std::simd::Simd<*const T, N>, std::simd::Simd<isize, N>>(move _4, move _17, move _14) -> [return: bb10, unwind unreachable];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions