Skip to content

ICE compiler/rustc_codegen_cranelift/src/constant.rs #1652

@matthiaskrgr

Description

@matthiaskrgr

snippet:

//@compile-flags: -Zcodegen-backend=cranelift
struct DataType {
    data: *mut (),
}
unsafe impl Sync for DataType {}
static DATA: DataType = unsafe {
    std::mem::transmute({
        fn ptr() {}
        (ptr as *const u8).wrapping_add(10)
    })
};
fn main() {}

Version information

rustc 1.97.0-nightly (68ffae46b 2026-04-25)
binary: rustc
commit-hash: 68ffae46b581747074413e4242ab0c6ecc4db4a9
commit-date: 2026-04-25
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Possibly related line of code:
https://github.com/rust-lang/rust/blob/68ffae46b581747074413e4242ab0c6ecc4db4a9/compiler/rustc_codegen_cranelift/src/constant.rs#L473-L485

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcodegen-backend=cranelift

Program output

warning: struct `DataType` is never constructed
 --> /tmp/icemaker_global_tempdir.fSJkGnXu3Ugm/rustc_testrunner_tmpdir_reporting.ge1G0ObvNCNu/mvce.rs:1:8
  |
1 | struct DataType {
  |        ^^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: static `DATA` is never used
 --> /tmp/icemaker_global_tempdir.fSJkGnXu3Ugm/rustc_testrunner_tmpdir_reporting.ge1G0ObvNCNu/mvce.rs:5:8
  |
5 | static DATA: DataType = unsafe {
  |        ^^^^


thread 'rustc' (841626) panicked at /rustc-dev/68ffae46b581747074413e4242ab0c6ecc4db4a9/compiler/rustc_codegen_cranelift/src/constant.rs:479:21:
assertion `left == right` failed
  left: 10
 right: 0
stack backtrace:
   0:     0x7f6673762edb - <<std[74a5d452ef4468e2]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[af918ca625322054]::fmt::Display>::fmt
   1:     0x7f6673e2d948 - core[af918ca625322054]::fmt::write
   2:     0x7f6673779b16 - <std[74a5d452ef4468e2]::sys::stdio::unix::Stderr as std[74a5d452ef4468e2]::io::Write>::write_fmt
   3:     0x7f6673739158 - std[74a5d452ef4468e2]::panicking::default_hook::{closure#0}
   4:     0x7f6673756543 - std[74a5d452ef4468e2]::panicking::default_hook
   5:     0x7f667272cb9c - std[74a5d452ef4468e2]::panicking::update_hook::<alloc[3c1e8b5c2310114c]::boxed::Box<rustc_driver_impl[65db170643483585]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f6673756822 - std[74a5d452ef4468e2]::panicking::panic_with_hook
   7:     0x7f6673739218 - std[74a5d452ef4468e2]::panicking::panic_handler::{closure#0}
   8:     0x7f667372d779 - std[74a5d452ef4468e2]::sys::backtrace::__rust_end_short_backtrace::<std[74a5d452ef4468e2]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f667373ac7d - __rustc[4d529550cd7027cf]::rust_begin_unwind
  10:     0x7f66703439fc - core[af918ca625322054]::panicking::panic_fmt
  11:     0x7f667204c3a3 - core[af918ca625322054]::panicking::assert_failed_inner
  12:     0x7f667332d91a - core[af918ca625322054]::panicking::assert_failed::<u128, u128>
  13:     0x7f6661291963 - <rustc_codegen_cranelift[aa14fe40da8db4b7]::constant::ConstantCx>::finalize
  14:     0x7f66612cbe7d - rustc_codegen_cranelift[aa14fe40da8db4b7]::constant::codegen_static
  15:     0x7f66612e3214 - rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::codegen_cgu_content
  16:     0x7f6661281bdb - rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::run_aot::{closure#3}::{closure#0}::{closure#0}
  17:     0x7f6661282bbb - rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::run_aot::{closure#3}::{closure#0}
  18:     0x7f66612f3529 - <core[af918ca625322054]::iter::adapters::filter_map::FilterMap<alloc[3c1e8b5c2310114c]::vec::into_iter::IntoIter<(usize, &rustc_middle[11ba238a743b416b]::mono::CodegenUnit)>, rustc_data_structures[c7559108f0771746]::sync::parallel::par_map<(usize, &rustc_middle[11ba238a743b416b]::mono::CodegenUnit), alloc[3c1e8b5c2310114c]::vec::Vec<(usize, &rustc_middle[11ba238a743b416b]::mono::CodegenUnit)>, rustc_data_structures[c7559108f0771746]::marker::IntoDynSyncSend<rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::OngoingModuleCodegen>, alloc[3c1e8b5c2310114c]::vec::Vec<rustc_data_structures[c7559108f0771746]::marker::IntoDynSyncSend<rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::OngoingModuleCodegen>>, rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#3}> as core[af918ca625322054]::iter::traits::iterator::Iterator>::next
  19:     0x7f66612eb2d8 - rustc_codegen_cranelift[aa14fe40da8db4b7]::driver::aot::run_aot
  20:     0x7f66612fd205 - <rustc_codegen_cranelift[aa14fe40da8db4b7]::CraneliftCodegenBackend as rustc_codegen_ssa[5a4428e3a3b57333]::traits::backend::CodegenBackend>::codegen_crate
  21:     0x7f6674f34572 - <rustc_interface[78b66ebcbd67330e]::queries::Linker>::codegen_and_build_linker
  22:     0x7f6674f2e833 - rustc_interface[78b66ebcbd67330e]::interface::run_compiler::<(), rustc_driver_impl[65db170643483585]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7f6674f54584 - std[74a5d452ef4468e2]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[78b66ebcbd67330e]::util::run_in_thread_with_globals<rustc_interface[78b66ebcbd67330e]::util::run_in_thread_pool_with_globals<rustc_interface[78b66ebcbd67330e]::interface::run_compiler<(), rustc_driver_impl[65db170643483585]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  24:     0x7f6674f54c6d - <std[74a5d452ef4468e2]::thread::lifecycle::spawn_unchecked<rustc_interface[78b66ebcbd67330e]::util::run_in_thread_with_globals<rustc_interface[78b66ebcbd67330e]::util::run_in_thread_pool_with_globals<rustc_interface[78b66ebcbd67330e]::interface::run_compiler<(), rustc_driver_impl[65db170643483585]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[af918ca625322054]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f6674f55aec - <std[74a5d452ef4468e2]::sys::thread::unix::Thread>::new::thread_start
  26:     0x7f666eaa597a - <unknown>
  27:     0x7f666eb292bc - <unknown>
  28:                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: rustc 1.97.0-nightly (68ffae46b 2026-04-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z codegen-backend=cranelift -Z dump-mir-dir=dir

query stack during panic:
end of query stack
warning: 2 warnings emitted


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