Skip to content

ICE compiler/rustc_codegen_llvm/src/common.rs 2 == 0 #147516

@matthiaskrgr

Description

@matthiaskrgr

Code

use std::mem::size_of;
fn distance_between<T>(dest: *const T, origin: *const T) -> usize {
    match size_of::<T> {
        _ => origin as usize,
    }
}
struct S;
const X: [S; 4] = [S, S, S, S];
const Y: *const S = X.as_ptr();
const Z: *const S = (Y as *const u8).wrapping_add(2) as *const S;
pub fn main() {
    println!("{}", distance_between(Z, Y))
}

Meta

rustc --version --verbose:

rustc 1.92.0-nightly (b6f0945e4 2025-10-08)
binary: rustc
commit-hash: b6f0945e4681bc4d2faa7c22c5f61dc36abf7dd2
commit-date: 2025-10-08
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Error output

<output>
Backtrace

warning: unused variable: `dest`
 --> /tmp/crash.rs:2:24
  |
2 | fn distance_between<T>(dest: *const T, origin: *const T) -> usize {
  |                        ^^^^ help: if this is intentional, prefix it with an underscore: `_dest`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (2735798) panicked at compiler/rustc_codegen_llvm/src/common.rs:284:29:
assertion `left == right` failed
  left: 2
 right: 0
stack backtrace:
   0:     0x7f13533d0013 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he87f93fe67261167
   1:     0x7f1353a01fbc - core::fmt::write::h0aa8549825819386
   2:     0x7f1353384b23 - std::io::Write::write_fmt::hd2151e08de10ff28
   3:     0x7f1353395fd2 - std::sys::backtrace::BacktraceLock::print::hf8464fe9ebf511be
   4:     0x7f135339c049 - std::panicking::default_hook::{{closure}}::hcd5485a5a088b562
   5:     0x7f135339bb73 - std::panicking::default_hook::hbece1839525cb3ec
   6:     0x7f13523b11c7 - std[abce4abe465e799c]::panicking::update_hook::<alloc[498c48ead57cdc4d]::boxed::Box<rustc_driver_impl[733c77d8475951ea]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f135339c46f - std::panicking::panic_with_hook::h660232911cf5a466
   8:     0x7f135339c22a - std::panicking::panic_handler::{{closure}}::ha66df24170df4402
   9:     0x7f1353396109 - std::sys::backtrace::__rust_end_short_backtrace::h8cf9a3411dc4e011
  10:     0x7f1353376c4d - __rustc[2820174ead26b8c1]::rust_begin_unwind
  11:     0x7f1350413ab0 - core::panicking::panic_fmt::h23b7ba79e91532e5
  12:     0x7f1351da3613 - core::panicking::assert_failed_inner::h410308ccf8fd7afe
  13:     0x7f1351da3417 - core::panicking::assert_failed::h2bf0e8c9a81b1395
  14:     0x7f1353a51259 - <rustc_codegen_ssa[19deb97213f21bba]::mir::FunctionCx<rustc_codegen_llvm[a55033960f7fe7e7]::builder::GenericBuilder<rustc_codegen_llvm[a55033960f7fe7e7]::context::FullCx>>>::eval_mir_constant_to_operand
  15:     0x7f135428f8bd - <rustc_codegen_ssa[19deb97213f21bba]::mir::FunctionCx<rustc_codegen_llvm[a55033960f7fe7e7]::builder::GenericBuilder<rustc_codegen_llvm[a55033960f7fe7e7]::context::FullCx>>>::codegen_operand
  16:     0x7f1354e05c3a - rustc_codegen_ssa[19deb97213f21bba]::mir::codegen_mir::<rustc_codegen_llvm[a55033960f7fe7e7]::builder::GenericBuilder<rustc_codegen_llvm[a55033960f7fe7e7]::context::FullCx>>
  17:     0x7f1353b34bab - rustc_codegen_llvm[a55033960f7fe7e7]::base::compile_codegen_unit::module_codegen
  18:     0x7f1354b3fb1f - <rustc_codegen_llvm[a55033960f7fe7e7]::LlvmCodegenBackend as rustc_codegen_ssa[19deb97213f21bba]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  19:     0x7f1354b3dace - <rustc_codegen_llvm[a55033960f7fe7e7]::LlvmCodegenBackend as rustc_codegen_ssa[19deb97213f21bba]::traits::backend::CodegenBackend>::codegen_crate
  20:     0x7f1354ca5130 - <rustc_interface[9f858680fc2dc059]::queries::Linker>::codegen_and_build_linker
  21:     0x7f1354ca2c70 - rustc_interface[9f858680fc2dc059]::passes::create_and_enter_global_ctxt::<core[4feb8f9d84ac7ee5]::option::Option<rustc_interface[9f858680fc2dc059]::queries::Linker>, rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  22:     0x7f1354c9a6c3 - <rustc_interface[9f858680fc2dc059]::passes::create_and_enter_global_ctxt<core[4feb8f9d84ac7ee5]::option::Option<rustc_interface[9f858680fc2dc059]::queries::Linker>, rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[4feb8f9d84ac7ee5]::ops::function::FnOnce<(&rustc_session[baee98d18babd558]::session::Session, rustc_middle[141878caf28dce8a]::ty::context::CurrentGcx, alloc[498c48ead57cdc4d]::sync::Arc<rustc_data_structures[65b165cb2c4fb825]::jobserver::Proxy>, &std[abce4abe465e799c]::sync::once_lock::OnceLock<rustc_middle[141878caf28dce8a]::ty::context::GlobalCtxt>, &rustc_data_structures[65b165cb2c4fb825]::sync::worker_local::WorkerLocal<rustc_middle[141878caf28dce8a]::arena::Arena>, &rustc_data_structures[65b165cb2c4fb825]::sync::worker_local::WorkerLocal<rustc_hir[8913ca6aecdf6079]::Arena>, rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  23:     0x7f1354c559fe - rustc_interface[9f858680fc2dc059]::interface::run_compiler::<(), rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}>::{closure#1}
  24:     0x7f1354b25f47 - std[abce4abe465e799c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[9f858680fc2dc059]::util::run_in_thread_with_globals<rustc_interface[9f858680fc2dc059]::util::run_in_thread_pool_with_globals<rustc_interface[9f858680fc2dc059]::interface::run_compiler<(), rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  25:     0x7f1354b25c28 - <<std[abce4abe465e799c]::thread::Builder>::spawn_unchecked_<rustc_interface[9f858680fc2dc059]::util::run_in_thread_with_globals<rustc_interface[9f858680fc2dc059]::util::run_in_thread_pool_with_globals<rustc_interface[9f858680fc2dc059]::interface::run_compiler<(), rustc_driver_impl[733c77d8475951ea]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[4feb8f9d84ac7ee5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x7f1354b2c3cd - std::sys::thread::unix::Thread::new::thread_start::h2b74411d58f20435
  27:     0x7f134e4969cb - <unknown>
  28:     0x7f134e51aa0c - <unknown>
  29:                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/matthias/vcs/github/CRED/rustc-ice-2025-10-09T09_51_49-2735780.txt` to your bug report

query stack during panic:
end of query stack
warning: 1 warning emitted

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-prioritizeIssue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions