rust-lang / rust-lang/rustc_codegen_cranelift

ICE compiler/rustc_codegen_cranelift/src/constant.rs

Open
#1,652 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
2.1k
Forks
157
Avg merge
1d 19h
Merged PRs (30d)
3

Description

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


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with compiler/rustc_codegen_cranelift/src/constant.rs around lines 473-485, then reproduce the ICE using the Rust snippet and -Zcodegen-backend=cranelift command from the issue. Trace the assertion in ConstantCx::finalize and verify that the reproducer compiles without the panic, with regression coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.