Skip to content

ICE: invalid immediate for given destination place #140332

Open
@wychlw

Description

@wychlw

Possible related issue:

  • #140100 Which has a different query stack, and require some data in the var
  • #131347 Remove the mut in it would be extremely like that.

The test case is generated by a fuzzer and reduced manually

Code

static mut S: [i8] = ["Some thing"; 1];
fn main() {
    assert_eq!(S, [0; 1]);
}

The command to reproduce should be: rustc -C opt-level=3 --edition 2024 -Zvalidate-mir

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (b4c8b0c3f 2025-04-25)
binary: rustc
commit-hash: b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3
commit-date: 2025-04-25
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

error: internal compiler error: /rustc/b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3/compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid immediate for given destination place: value Scalar(alloc1) 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/b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3/compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
Box<dyn Any>
...
query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

error[E0277]: the size for values of type `[i8]` cannot be known at compilation time
 --> tmp/out3/gen_30479.rs:1:15
  |
1 | static mut S: [i8] = ["Some thing"; 1];
  |               ^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[i8]`
  = note: statics and constants must have a statically known size

error[E0308]: mismatched types
 --> tmp/out3/gen_30479.rs:1:23
  |
1 | static mut S: [i8] = ["Some thing"; 1];
  |                       ^^^^^^^^^^^^ expected `i8`, found `&str`

error[E0308]: mismatched types
 --> tmp/out3/gen_30479.rs:1:22
  |
1 | static mut S: [i8] = ["Some thing"; 1];
  |                      ^^^^^^^^^^^^^^^^^ expected `[i8]`, found `[i8; 1]`

error[E0133]: use of mutable static is unsafe and requires unsafe block
 --> tmp/out3/gen_30479.rs:3:16
  |
3 |     assert_eq!(S, [0; 1]);
  |                ^ use of mutable static
  |
  = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior

error: internal compiler error: /rustc/b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3/compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid immediate for given destination place: value Scalar(alloc1) 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/b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3/compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
Box<dyn Any>
stack backtrace:
   0:     0x7512466ef453 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3810760a61645fc6
   1:     0x751246e05ac7 - core::fmt::write::h0088928f76d30077
   2:     0x7512481f3311 - std::io::Write::write_fmt::h78de47c93a2470e9
   3:     0x7512466ef2b2 - std::sys::backtrace::BacktraceLock::print::hd536e5d51513ad76
   4:     0x7512466f30fa - std::panicking::default_hook::{{closure}}::h6492940019273362
   5:     0x7512466f2c7f - std::panicking::default_hook::h96833e74e5b18821
   6:     0x7512457756b3 - std[30e4b062834ac322]::panicking::update_hook::<alloc[8846d236b4ac61d9]::boxed::Box<rustc_driver_impl[6daf40cdc4897975]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7512466f3973 - std::panicking::rust_panic_with_hook::h33332f412fb2ffa9
   8:     0x7512457b1681 - std[30e4b062834ac322]::panicking::begin_panic::<rustc_errors[757a7ab50bea937f]::ExplicitBug>::{closure#0}
   9:     0x7512457a56b6 - std[30e4b062834ac322]::sys::backtrace::__rust_end_short_backtrace::<std[30e4b062834ac322]::panicking::begin_panic<rustc_errors[757a7ab50bea937f]::ExplicitBug>::{closure#0}, !>
  10:     0x7512457a1d99 - std[30e4b062834ac322]::panicking::begin_panic::<rustc_errors[757a7ab50bea937f]::ExplicitBug>
  11:     0x7512457bba51 - <rustc_errors[757a7ab50bea937f]::diagnostic::BugAbort as rustc_errors[757a7ab50bea937f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x751245df70ea - rustc_middle[14964323be5c6d14]::util::bug::opt_span_bug_fmt::<rustc_span[9b2946c57ebb402d]::span_encoding::Span>::{closure#0}
  13:     0x751245dd221a - rustc_middle[14964323be5c6d14]::ty::context::tls::with_opt::<rustc_middle[14964323be5c6d14]::util::bug::opt_span_bug_fmt<rustc_span[9b2946c57ebb402d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x751245dd208b - rustc_middle[14964323be5c6d14]::ty::context::tls::with_context_opt::<rustc_middle[14964323be5c6d14]::ty::context::tls::with_opt<rustc_middle[14964323be5c6d14]::util::bug::opt_span_bug_fmt<rustc_span[9b2946c57ebb402d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x75124308aee0 - rustc_middle[14964323be5c6d14]::util::bug::bug_fmt
  16:     0x751247a28e44 - <rustc_const_eval[5548788696870cc5]::interpret::eval_context::InterpCx<rustc_const_eval[5548788696870cc5]::const_eval::dummy_machine::DummyMachine>>::write_immediate_to_mplace_no_validate
  17:     0x75124464c59b - <rustc_mir_transform[a95ce98e4e91b81e]::gvn::VnState as rustc_middle[14964323be5c6d14]::mir::visit::MutVisitor>::visit_statement
  18:     0x7512446450ab - <rustc_mir_transform[a95ce98e4e91b81e]::gvn::GVN as rustc_mir_transform[a95ce98e4e91b81e]::pass_manager::MirPass>::run_pass
  19:     0x751246e039fb - rustc_mir_transform[a95ce98e4e91b81e]::pass_manager::run_passes_inner
  20:     0x7512477efd1f - rustc_mir_transform[a95ce98e4e91b81e]::optimized_mir
  21:     0x7512477ef30d - rustc_query_impl[fe0de826094a3706]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe0de826094a3706]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[14964323be5c6d14]::query::erase::Erased<[u8; 8usize]>>
  22:     0x75124714c56f - rustc_query_system[c83524e34b3ee13b]::query::plumbing::try_execute_query::<rustc_query_impl[fe0de826094a3706]::DynamicConfig<rustc_query_system[c83524e34b3ee13b]::query::caches::DefIdCache<rustc_middle[14964323be5c6d14]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fe0de826094a3706]::plumbing::QueryCtxt, false>
  23:     0x75124714b99d - rustc_query_impl[fe0de826094a3706]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7512475ac7ef - <rustc_middle[14964323be5c6d14]::ty::context::TyCtxt>::instance_mir
  25:     0x75124790df8c - rustc_interface[76005b124f6a7e54]::passes::run_required_analyses
  26:     0x751247cf7a1e - rustc_interface[76005b124f6a7e54]::passes::analysis
  27:     0x751247cf79ed - rustc_query_impl[fe0de826094a3706]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe0de826094a3706]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[14964323be5c6d14]::query::erase::Erased<[u8; 0usize]>>
  28:     0x751247cfd4fd - rustc_query_system[c83524e34b3ee13b]::query::plumbing::try_execute_query::<rustc_query_impl[fe0de826094a3706]::DynamicConfig<rustc_query_system[c83524e34b3ee13b]::query::caches::SingleCache<rustc_middle[14964323be5c6d14]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[fe0de826094a3706]::plumbing::QueryCtxt, false>
  29:     0x751247cfd1f8 - rustc_query_impl[fe0de826094a3706]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  30:     0x751247fab580 - rustc_interface[76005b124f6a7e54]::passes::create_and_enter_global_ctxt::<core[52168106b816615d]::option::Option<rustc_interface[76005b124f6a7e54]::queries::Linker>, rustc_driver_impl[6daf40cdc4897975]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  31:     0x751247ec2504 - rustc_interface[76005b124f6a7e54]::interface::run_compiler::<(), rustc_driver_impl[6daf40cdc4897975]::run_compiler::{closure#0}>::{closure#1}
  32:     0x751247ea2d74 - std[30e4b062834ac322]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[76005b124f6a7e54]::util::run_in_thread_with_globals<rustc_interface[76005b124f6a7e54]::util::run_in_thread_pool_with_globals<rustc_interface[76005b124f6a7e54]::interface::run_compiler<(), rustc_driver_impl[6daf40cdc4897975]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  33:     0x751247ea31b4 - <<std[30e4b062834ac322]::thread::Builder>::spawn_unchecked_<rustc_interface[76005b124f6a7e54]::util::run_in_thread_with_globals<rustc_interface[76005b124f6a7e54]::util::run_in_thread_pool_with_globals<rustc_interface[76005b124f6a7e54]::interface::run_compiler<(), rustc_driver_impl[6daf40cdc4897975]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[52168106b816615d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x751247ea45ab - std::sys::pal::unix::thread::Thread::new::thread_start::h32ef7da320b5e71e
  35:     0x751241ca3708 - <unknown>
  36:     0x751241d27aac - <unknown>
  37:                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.88.0-nightly (b4c8b0c3f 2025-04-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -Z validate-mir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0133, E0277, E0308.
For more information about an error, try `rustc --explain E0133`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zvalidate-mirUnstable option: MIR validationA-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions