rust-lang / rust-lang/rust

ICE: `invalid field type in Immediate::offset: value Scalar(0x0000000000000000) does not match ABI ScalarPair(..)`

Open
#136,442 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir-opt A-mir-opt-inlining C-bug I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

snippet:

//@compile-flags: -Zmir-enable-passes=+Inline -Zmir-enable-passes=+JumpThreading --crate-type=lib
pub fn problem_thingy(items: &mut impl Iterator<Item = str>) {
    let mut peeker = items.peekable();
    match peeker.peek() {
        Some(_) => (),
        None => return (),
    }
}

Version information

rustc 1.86.0-nightly (6dd75f0d6 2025-02-02)
binary: rustc
commit-hash: 6dd75f0d6802f56564f5f9c947a85ded286d3986
commit-date: 2025-02-02
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-enable-passes=+Inline -Zmir-enable-passes=+JumpThreading --crate-type=lib

Program output

error: internal compiler error: /rustc/6dd75f0d6802f56564f5f9c947a85ded286d3986/compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid field type in Immediate::offset: value Scalar(0x0000000000000000) does not match ABI ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }))


thread 'rustc' panicked at /rustc/6dd75f0d6802f56564f5f9c947a85ded286d3986/compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
Box<dyn Any>
stack backtrace:
   0:     0x74a71602ed50 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hbfd757a12de5328f
   1:     0x74a716814826 - core::fmt::write::h8a36a2b16afbec2c
   2:     0x74a717b39a51 - std::io::Write::write_fmt::h405e3b74afe27f82
   3:     0x74a71602ebb2 - std::sys::backtrace::BacktraceLock::print::h83c9aa10f541661c
   4:     0x74a716031032 - std::panicking::default_hook::{{closure}}::h720ed0d152826500
   5:     0x74a716030eba - std::panicking::default_hook::hfc73f50ca652e2b3
   6:     0x74a715189389 - std[ff511cecd2b9d7cf]::panicking::update_hook::<alloc[c4f21c44eb49384f]::boxed::Box<rustc_driver_impl[b88f56deeb7372ac]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x74a716031bb3 - std::panicking::rust_panic_with_hook::h73e8d76e64e48546
   8:     0x74a7151c4051 - std[ff511cecd2b9d7cf]::panicking::begin_panic::<rustc_errors[bb44e506870335f6]::ExplicitBug>::{closure#0}
   9:     0x74a7151b8fc6 - std[ff511cecd2b9d7cf]::sys::backtrace::__rust_end_short_backtrace::<std[ff511cecd2b9d7cf]::panicking::begin_panic<rustc_errors[bb44e506870335f6]::ExplicitBug>::{closure#0}, !>
  10:     0x74a7151b8fad - std[ff511cecd2b9d7cf]::panicking::begin_panic::<rustc_errors[bb44e506870335f6]::ExplicitBug>
  11:     0x74a7151cdfa1 - <rustc_errors[bb44e506870335f6]::diagnostic::BugAbort as rustc_errors[bb44e506870335f6]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74a7157b3bf3 - rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt::<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}
  13:     0x74a71579cb7a - rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_opt::<rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x74a71579ca0b - rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_context_opt::<rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_opt<rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x74a71394fe70 - rustc_middle[f2fffebf67d4dac6]::util::bug::bug_fmt
  16:     0x74a71823d7cd - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::Immediate>::assert_matches_abi::<rustc_const_eval[fd121c9846faaa35]::interpret::eval_context::InterpCx<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>>.cold
  17:     0x74a71734c022 - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[fd121c9846faaa35]::interpret::eval_context::InterpCx<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>>
  18:     0x74a71734aa0d - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::OpTy as rustc_const_eval[fd121c9846faaa35]::interpret::projection::Projectable<rustc_middle[f2fffebf67d4dac6]::mir::interpret::pointer::CtfeProvenance>>::offset_with_meta::<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>
  19:     0x74a717367411 - <rustc_mir_dataflow[bb806dd31a4a8e17]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[fd121c9846faaa35]::interpret::operand::OpTy, <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_constant::{closure#1}>
  20:     0x74a717363c88 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_operand
  21:     0x74a717364283 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::find_opportunity
  22:     0x74a717365407 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::find_opportunity
  23:     0x74a7173619c4 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::JumpThreading as rustc_mir_transform[8d321f23de625b13]::pass_manager::MirPass>::run_pass
  24:     0x74a7168044a2 - rustc_mir_transform[8d321f23de625b13]::pass_manager::run_passes_inner
  25:     0x74a716d5068e - rustc_mir_transform[8d321f23de625b13]::optimized_mir
  26:     0x74a716d4fe8d - rustc_query_impl[d8c178d2a03c64a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d8c178d2a03c64a0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>
  27:     0x74a716b30f9f - rustc_query_system[6dc7d387dd994d75]::query::plumbing::try_execute_query::<rustc_query_impl[d8c178d2a03c64a0]::DynamicConfig<rustc_query_system[6dc7d387dd994d75]::query::caches::DefIdCache<rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d8c178d2a03c64a0]::plumbing::QueryCtxt, false>
  28:     0x74a716b3039f - rustc_query_impl[d8c178d2a03c64a0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  29:     0x74a71738a6a9 - rustc_middle[f2fffebf67d4dac6]::query::plumbing::query_get_at::<rustc_query_system[6dc7d387dd994d75]::query::caches::DefIdCache<rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>>
  30:     0x74a717391a71 - <rustc_metadata[5919056398511050]::rmeta::encoder::EncodeContext>::encode_crate_root
  31:     0x74a71799a468 - rustc_metadata[5919056398511050]::rmeta::encoder::encode_metadata
  32:     0x74a7177bf036 - rustc_metadata[5919056398511050]::fs::encode_and_write_metadata
  33:     0x74a7177bdece - <rustc_interface[2006dbae419e0802]::queries::Linker>::codegen_and_build_linker
  34:     0x74a7177625df - rustc_interface[2006dbae419e0802]::passes::create_and_enter_global_ctxt::<core[27041657fc19ee73]::option::Option<rustc_interface[2006dbae419e0802]::queries::Linker>, rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  35:     0x74a717741c73 - rustc_interface[2006dbae419e0802]::interface::run_compiler::<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}
  36:     0x74a7176a83f5 - std[ff511cecd2b9d7cf]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2006dbae419e0802]::util::run_in_thread_with_globals<rustc_interface[2006dbae419e0802]::util::run_in_thread_pool_with_globals<rustc_interface[2006dbae419e0802]::interface::run_compiler<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x74a7176a80d9 - <<std[ff511cecd2b9d7cf]::thread::Builder>::spawn_unchecked_<rustc_interface[2006dbae419e0802]::util::run_in_thread_with_globals<rustc_interface[2006dbae419e0802]::util::run_in_thread_pool_with_globals<rustc_interface[2006dbae419e0802]::interface::run_compiler<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[27041657fc19ee73]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x74a7176a786b - std::sys::pal::unix::thread::Thread::new::thread_start::hb57557dfe1a8d225
  39:     0x74a7118a339d - <unknown>
  40:     0x74a71192849c - <unknown>
  41:                0x0 - <unknown>

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.86.0-nightly (6dd75f0d6 2025-02-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-enable-passes=+Inline -Z mir-enable-passes=+JumpThreading --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `problem_thingy`
end of query stack
error: aborting due to 1 previous error


cc https://github.com/rust-lang/rust/issues/135020

Contributor guide

Open the contributing guide

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

Reproduce the ICE with the provided a.rs snippet and rustc flags, then inspect compiler/rustc_const_eval/src/interpret/operand.rs:157 and the JumpThreading path named in the query stack. Trace how optimized MIR for problem_thingy reaches Immediate::offset and verify the fix with the same command. Done means the compiler no longer aborts on this valid input with Inline and JumpThreading enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.