Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpret: Immediate::offset: use shared sanity-check function to ensure invariant #131068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

This applies the relatively new assert_matches_abi check in the offset operation on immediates, which makes sure that if offsets are used to alter the layout (which is possible because the field layout is arbitrarily picked by the caller), this is not done in a way that breaks the invariant of the Immediate type.

This currently ICEs in a GVN mir-opt test, in this call:

value.offset(Size::ZERO, to, &self.ecx).ok()?

I am fairly sure that's #131064, which is the bug that prompted me to add these assertions now. IOW, the assertions would have helped to find #131064 earlier, which is a good thing. :)

Blocked on a fix for #131064.

@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2024

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 30, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2024

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
invalid field type in Immediate::offset: scalar value should be an integer, but has provenance
stack backtrace:
   0:     0x7f68980b2541 - <<std[6c750a05e3c6755a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b142286047025e8]::fmt::Display>::fmt
   1:     0x7f689810cbd0 - core[b142286047025e8]::fmt::write
   2:     0x7f68980a62e9 - <std[6c750a05e3c6755a]::sys::pal::unix::stdio::Stderr as std[6c750a05e3c6755a]::io::Write>::write_fmt
   3:     0x7f68980b23e2 - <std[6c750a05e3c6755a]::sys::backtrace::BacktraceLock>::print
   4:     0x7f68980b4e6a - std[6c750a05e3c6755a]::panicking::default_hook::{closure#1}
   5:     0x7f68980b4bfd - std[6c750a05e3c6755a]::panicking::default_hook
   6:     0x7f6898c51662 - <alloc[dee4b9212dfad676]::boxed::Box<rustc_driver_impl[1ecc49d2b502cd52]::install_ice_hook::{closure#0}> as core[b142286047025e8]::ops::function::Fn<(&dyn for<'a, 'b> core[b142286047025e8]::ops::function::Fn<(&'a std[6c750a05e3c6755a]::panic::PanicHookInfo<'b>,), Output = ()> + core[b142286047025e8]::marker::Sync + core[b142286047025e8]::marker::Send, &std[6c750a05e3c6755a]::panic::PanicHookInfo)>>::call
   7:     0x7f68980b56c8 - std[6c750a05e3c6755a]::panicking::rust_panic_with_hook
   8:     0x7f68980b53ee - std[6c750a05e3c6755a]::panicking::begin_panic_handler::{closure#0}
   9:     0x7f68980b2b99 - std[6c750a05e3c6755a]::sys::backtrace::__rust_end_short_backtrace::<std[6c750a05e3c6755a]::panicking::begin_panic_handler::{closure#0}, !>
  11:     0x7f68980671c0 - core[b142286047025e8]::panicking::panic_fmt
  11:     0x7f68980671c0 - core[b142286047025e8]::panicking::panic_fmt
  12:     0x7f6899dd03a0 - <rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::operand::Immediate>::assert_matches_abi::<rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::eval_context::InterpCx<rustc_const_eval[c9ffe1e56fe6c6fc]::const_eval::dummy_machine::DummyMachine>>
  13:     0x7f6899dcad21 - <rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::eval_context::InterpCx<rustc_const_eval[c9ffe1e56fe6c6fc]::const_eval::dummy_machine::DummyMachine>>
  14:     0x7f6899ddaacf - <rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::operand::OpTy as rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::projection::Projectable<rustc_middle[8b8bdf7c6e785626]::mir::interpret::pointer::CtfeProvenance>>::offset_with_meta::<rustc_const_eval[c9ffe1e56fe6c6fc]::const_eval::dummy_machine::DummyMachine>
  15:     0x7f6899dde874 - <rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::operand::OpTy as rustc_const_eval[c9ffe1e56fe6c6fc]::interpret::projection::Projectable<rustc_middle[8b8bdf7c6e785626]::mir::interpret::pointer::CtfeProvenance>>::offset::<rustc_const_eval[c9ffe1e56fe6c6fc]::const_eval::dummy_machine::DummyMachine>
  16:     0x7f6899f17ede - <rustc_mir_transform[89643dce665d9be5]::gvn::VnState>::eval_to_const::{closure#0}
  17:     0x7f6899f14d58 - <rustc_mir_transform[89643dce665d9be5]::gvn::VnState>::insert
  18:     0x7f6899f1ff2e - <rustc_mir_transform[89643dce665d9be5]::gvn::VnState>::simplify_rvalue::{closure#0}
  19:     0x7f6899f1d136 - <rustc_mir_transform[89643dce665d9be5]::gvn::VnState>::simplify_rvalue
  20:     0x7f6899ea266c - <rustc_mir_transform[89643dce665d9be5]::ssa::SsaLocals>::for_each_assignment_mut::<<rustc_mir_transform[89643dce665d9be5]::gvn::GVN as rustc_mir_transform[89643dce665d9be5]::pass_manager::MirPass>::run_pass::{closure#0}>
  21:     0x7f6899f127cc - <rustc_mir_transform[89643dce665d9be5]::gvn::GVN as rustc_mir_transform[89643dce665d9be5]::pass_manager::MirPass>::run_pass
  22:     0x7f6899c9f66f - rustc_mir_transform[89643dce665d9be5]::pass_manager::run_passes_inner
  23:     0x7f6899cd8a2a - rustc_mir_transform[89643dce665d9be5]::optimized_mir
  24:     0x7f689af281f7 - rustc_query_impl[e3ac0b70dbe1a6f8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e3ac0b70dbe1a6f8]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b8bdf7c6e785626]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f689b25d4f9 - <rustc_query_impl[e3ac0b70dbe1a6f8]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[b142286047025e8]::ops::function::FnOnce<(rustc_middle[8b8bdf7c6e785626]::ty::context::TyCtxt, rustc_span[91514ba07070f9c7]::def_id::DefId)>>::call_once
  26:     0x7f689b314a02 - rustc_query_system[b0b7bc6cadcde36d]::query::plumbing::try_execute_query::<rustc_query_impl[e3ac0b70dbe1a6f8]::DynamicConfig<rustc_query_system[b0b7bc6cadcde36d]::query::caches::DefIdCache<rustc_middle[8b8bdf7c6e785626]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e3ac0b70dbe1a6f8]::plumbing::QueryCtxt, false>
  27:     0x7f689b273bcd - rustc_query_impl[e3ac0b70dbe1a6f8]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f689c16d66e - rustc_middle[8b8bdf7c6e785626]::query::plumbing::query_get_at::<rustc_query_system[b0b7bc6cadcde36d]::query::caches::DefIdCache<rustc_middle[8b8bdf7c6e785626]::query::erase::Erased<[u8; 8usize]>>>
  29:     0x7f689c17306e - <rustc_metadata[68df45c71202f531]::rmeta::encoder::EncodeContext>::encode_crate_root
  30:     0x7f689c182c62 - rustc_metadata[68df45c71202f531]::rmeta::encoder::encode_metadata
  31:     0x7f689c1d2460 - rustc_metadata[68df45c71202f531]::fs::encode_and_write_metadata
  33:     0x7f6898f4c382 - <rustc_interface[b7f2e8500d645853]::queries::Linker>::codegen_and_build_linker
  34:     0x7f6898c222ed - <rustc_middle[8b8bdf7c6e785626]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}::{closure#1}::{closure#6}, core[b142286047025e8]::result::Result<core[b142286047025e8]::option::Option<rustc_interface[b7f2e8500d645853]::queries::Linker>, rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>
  35:     0x7f6898c715d5 - <rustc_interface[b7f2e8500d645853]::queries::QueryResult<&rustc_middle[8b8bdf7c6e785626]::ty::context::GlobalCtxt>>::enter::<core[b142286047025e8]::result::Result<core[b142286047025e8]::option::Option<rustc_interface[b7f2e8500d645853]::queries::Linker>, rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}::{closure#1}::{closure#6}>
  36:     0x7f6898d1d0c7 - <rustc_interface[b7f2e8500d645853]::interface::Compiler>::enter::<rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}::{closure#1}, core[b142286047025e8]::result::Result<core[b142286047025e8]::option::Option<rustc_interface[b7f2e8500d645853]::queries::Linker>, rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>
  36:     0x7f6898d1d0c7 - <rustc_interface[b7f2e8500d645853]::interface::Compiler>::enter::<rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}::{closure#1}, core[b142286047025e8]::result::Result<core[b142286047025e8]::option::Option<rustc_interface[b7f2e8500d645853]::queries::Linker>, rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>
  37:     0x7f6898c61d47 - <scoped_tls[d8eeb689ffeb4163]::ScopedKey<rustc_span[91514ba07070f9c7]::SessionGlobals>>::set::<rustc_interface[b7f2e8500d645853]::util::run_in_thread_with_globals<rustc_interface[b7f2e8500d645853]::util::run_in_thread_pool_with_globals<rustc_interface[b7f2e8500d645853]::interface::run_compiler<core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}>::{closure#1}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>
  38:     0x7f6898c4123c - rustc_span[91514ba07070f9c7]::create_session_globals_then::<core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_interface[b7f2e8500d645853]::util::run_in_thread_with_globals<rustc_interface[b7f2e8500d645853]::util::run_in_thread_pool_with_globals<rustc_interface[b7f2e8500d645853]::interface::run_compiler<core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}>::{closure#1}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  39:     0x7f6898c6ce52 - std[6c750a05e3c6755a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b7f2e8500d645853]::util::run_in_thread_with_globals<rustc_interface[b7f2e8500d645853]::util::run_in_thread_pool_with_globals<rustc_interface[b7f2e8500d645853]::interface::run_compiler<core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}>::{closure#1}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>
  40:     0x7f6898c4ee9f - <<std[6c750a05e3c6755a]::thread::Builder>::spawn_unchecked_<rustc_interface[b7f2e8500d645853]::util::run_in_thread_with_globals<rustc_interface[b7f2e8500d645853]::util::run_in_thread_pool_with_globals<rustc_interface[b7f2e8500d645853]::interface::run_compiler<core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>, rustc_driver_impl[1ecc49d2b502cd52]::run_compiler::{closure#0}>::{closure#1}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b142286047025e8]::result::Result<(), rustc_span[91514ba07070f9c7]::ErrorGuaranteed>>::{closure#1} as core[b142286047025e8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f68980c1425 - <std[6c750a05e3c6755a]::sys::pal::unix::thread::Thread>::new::thread_start
  43:     0x7f6897f15850 - <unknown>
  44:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.
---
warning: the ICE couldn't be written to `/checkout/library/rustc-ice-2024-09-30T16_16_50-11461.txt`: Read-only file system (os error 30)

note: rustc 1.83.0-nightly (e1437788d 2024-09-30) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debug-assertions=on -C symbol-mangling-version=v0 -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -Z inline-mir -Z inline-mir-preserve-debug -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C embed-bitcode=yes -C force-frame-pointers=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
query stack during panic:
#0 [optimized_mir] optimizing MIR for `sync::<impl at alloc/src/sync.rs:3492:1: 3492:38>::default`
error: could not compile `alloc` (lib)
Build completed unsuccessfully in 0:05:33
  local time: Mon Sep 30 16:16:54 UTC 2024
  network time: Mon, 30 Sep 2024 16:16:55 GMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants