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

Attempt to read from stolen value with -Zmir-enable-passes=+Inline, but not -Zinline-mir #116291

Closed
saethlin opened this issue Sep 30, 2023 · 4 comments
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@saethlin
Copy link
Member

Code

fn main() {
    let func = || 123u8;
    func();
}
rustc +nightly -Zmir-opt-level=0 -Zmir-enable-passes=+Inline

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (8ce4540bd 2023-09-29)
binary: rustc
commit-hash: 8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72
commit-date: 2023-09-29
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.2

Error output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/inline/cycle.rs:156:27:
attempted to read from stolen value: rustc_middle::mir::Body
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_transform/src/inline/cycle.rs:156:27:
attempted to read from stolen value: rustc_middle::mir::Body
stack backtrace:
   0:     0x7ff80af6433c - std::backtrace_rs::backtrace::libunwind::trace::h2047b82b78957b16
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff80af6433c - std::backtrace_rs::backtrace::trace_unsynchronized::he06321801fe2ac72
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff80af6433c - std::sys_common::backtrace::_print_fmt::h3028a39ff66599c0
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7ff80af6433c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd2dc6ab4971909d6
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff80afc9f9c - core::fmt::rt::Argument::fmt::hae02ab67a447b751
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/core/src/fmt/rt.rs:138:9
   5:     0x7ff80afc9f9c - core::fmt::write::h156c0157377de849
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/core/src/fmt/mod.rs:1114:21
   6:     0x7ff80af570be - std::io::Write::write_fmt::hfda671e33214dbc9
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/io/mod.rs:1763:15
   7:     0x7ff80af64124 - std::sys_common::backtrace::_print::he2b418ab91e1b6bc
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff80af64124 - std::sys_common::backtrace::print::h39dd53e781dbe62d
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff80af67003 - std::panicking::default_hook::{{closure}}::hac1d0be96ef52b84
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/panicking.rs:272:22
  10:     0x7ff80af66d24 - std::panicking::default_hook::h430f734618200aae
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/panicking.rs:292:9
  11:     0x7ff80e0f681f - std[9021ab7eb1800470]::panicking::update_hook::<alloc[b36931eabff6d458]::boxed::Box<rustc_driver_impl[3b155c69176e0130]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ff80af67831 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0ec3fa0b3629c93a
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/alloc/src/boxed.rs:2021:9
  13:     0x7ff80af67831 - std::panicking::rust_panic_with_hook::hdb0a7131bd1f25e3
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/panicking.rs:735:13
  14:     0x7ff80af675b1 - std::panicking::begin_panic_handler::{{closure}}::h2b42e435eaa711ee
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/panicking.rs:609:13
  15:     0x7ff80af64866 - std::sys_common::backtrace::__rust_end_short_backtrace::h3652b1b01bc073c5
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7ff80af67302 - rust_begin_unwind
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/panicking.rs:597:5
  17:     0x7ff80afc6625 - core::panicking::panic_fmt::h7198c5e2f1cf748f
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/core/src/panicking.rs:72:14
  18:     0x7ff80d3ef300 - rustc_mir_transform[ec90b8a83414cedc]::inline::cycle::mir_inliner_callees
  19:     0x7ff80c5e5715 - rustc_query_impl[fe2b8f031e651193]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe2b8f031e651193]::query_impl::mir_inliner_callees::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 16usize]>>
  20:     0x7ff80c5e56e2 - <rustc_query_impl[fe2b8f031e651193]::query_impl::mir_inliner_callees::dynamic_query::{closure#2} as core[eac01cc03d7c90b2]::ops::function::FnOnce<(rustc_middle[7d6c6611b495d02e]::ty::context::TyCtxt, rustc_middle[7d6c6611b495d02e]::ty::instance::InstanceDef)>>::call_once
  21:     0x7ff80d33375a - rustc_query_system[dfd8d19a16263799]::query::plumbing::try_execute_query::<rustc_query_impl[fe2b8f031e651193]::DynamicConfig<rustc_query_system[dfd8d19a16263799]::query::caches::DefaultCache<rustc_middle[7d6c6611b495d02e]::ty::instance::InstanceDef, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[fe2b8f031e651193]::plumbing::QueryCtxt, false>
  22:     0x7ff80d333454 - rustc_query_impl[fe2b8f031e651193]::query_impl::mir_inliner_callees::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7ff80cff0605 - rustc_mir_transform[ec90b8a83414cedc]::inline::cycle::mir_callgraph_reachable::process
  24:     0x7ff80d59755f - rustc_mir_transform[ec90b8a83414cedc]::inline::cycle::mir_callgraph_reachable
  25:     0x7ff80d13eb3c - rustc_query_impl[fe2b8f031e651193]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe2b8f031e651193]::query_impl::mir_callgraph_reachable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 1usize]>>
  26:     0x7ff80d13eb04 - <rustc_query_impl[fe2b8f031e651193]::query_impl::mir_callgraph_reachable::dynamic_query::{closure#2} as core[eac01cc03d7c90b2]::ops::function::FnOnce<(rustc_middle[7d6c6611b495d02e]::ty::context::TyCtxt, (rustc_middle[7d6c6611b495d02e]::ty::instance::Instance, rustc_span[a848110e357b7e8b]::def_id::LocalDefId))>>::call_once
  27:     0x7ff80d551c31 - rustc_query_system[dfd8d19a16263799]::query::plumbing::try_execute_query::<rustc_query_impl[fe2b8f031e651193]::DynamicConfig<rustc_query_system[dfd8d19a16263799]::query::caches::DefaultCache<(rustc_middle[7d6c6611b495d02e]::ty::instance::Instance, rustc_span[a848110e357b7e8b]::def_id::LocalDefId), rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fe2b8f031e651193]::plumbing::QueryCtxt, false>
  28:     0x7ff80d55191c - rustc_query_impl[fe2b8f031e651193]::query_impl::mir_callgraph_reachable::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7ff80d0c5cec - <rustc_mir_transform[ec90b8a83414cedc]::inline::Inliner>::try_inlining
  30:     0x7ff80d0c4239 - <rustc_mir_transform[ec90b8a83414cedc]::inline::Inliner>::process_blocks
  31:     0x7ff80d0c3c2a - <rustc_mir_transform[ec90b8a83414cedc]::inline::Inline as rustc_middle[7d6c6611b495d02e]::mir::MirPass>::run_pass
  32:     0x7ff80c7bc031 - rustc_mir_transform[ec90b8a83414cedc]::pass_manager::run_passes
  33:     0x7ff80c7bb6ce - rustc_mir_transform[ec90b8a83414cedc]::optimized_mir
  34:     0x7ff80c27a7e8 - rustc_query_impl[fe2b8f031e651193]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe2b8f031e651193]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7ff80c27a7b1 - <rustc_query_impl[fe2b8f031e651193]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[eac01cc03d7c90b2]::ops::function::FnOnce<(rustc_middle[7d6c6611b495d02e]::ty::context::TyCtxt, rustc_span[a848110e357b7e8b]::def_id::DefId)>>::call_once
  36:     0x7ff80c2484c0 - rustc_query_system[dfd8d19a16263799]::query::plumbing::try_execute_query::<rustc_query_impl[fe2b8f031e651193]::DynamicConfig<rustc_query_system[dfd8d19a16263799]::query::caches::DefaultCache<rustc_span[a848110e357b7e8b]::def_id::DefId, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fe2b8f031e651193]::plumbing::QueryCtxt, false>
  37:     0x7ff80da51d92 - rustc_query_impl[fe2b8f031e651193]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7ff80c614020 - <rustc_middle[7d6c6611b495d02e]::ty::context::TyCtxt>::instance_mir
  39:     0x7ff80cee32a2 - rustc_monomorphize[825a039f47682177]::collector::collect_used_items
  40:     0x7ff80cee0685 - rustc_monomorphize[825a039f47682177]::collector::collect_items_rec
  41:     0x7ff80d5d4ea8 - rustc_data_structures[82d39ef94a006aa1]::sync::parallel::disabled::par_for_each_in::<alloc[b36931eabff6d458]::vec::Vec<rustc_middle[7d6c6611b495d02e]::mir::mono::MonoItem>, rustc_monomorphize[825a039f47682177]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  42:     0x7ff80d5d4240 - <rustc_session[76460c32d01a7a92]::session::Session>::time::<(), rustc_monomorphize[825a039f47682177]::collector::collect_crate_mono_items::{closure#1}>
  43:     0x7ff80d5d3e88 - rustc_monomorphize[825a039f47682177]::collector::collect_crate_mono_items
  44:     0x7ff80d5d2458 - rustc_monomorphize[825a039f47682177]::partitioning::collect_and_partition_mono_items
  45:     0x7ff80d6dfde9 - rustc_query_impl[fe2b8f031e651193]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fe2b8f031e651193]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 24usize]>>
  46:     0x7ff80d6dfdbd - <rustc_query_impl[fe2b8f031e651193]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[eac01cc03d7c90b2]::ops::function::FnOnce<(rustc_middle[7d6c6611b495d02e]::ty::context::TyCtxt, ())>>::call_once
  47:     0x7ff80d854b57 - rustc_query_system[dfd8d19a16263799]::query::plumbing::try_execute_query::<rustc_query_impl[fe2b8f031e651193]::DynamicConfig<rustc_query_system[dfd8d19a16263799]::query::caches::SingleCache<rustc_middle[7d6c6611b495d02e]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[fe2b8f031e651193]::plumbing::QueryCtxt, false>
  48:     0x7ff80da6df92 - rustc_query_impl[fe2b8f031e651193]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7ff80d2e6e3b - rustc_codegen_ssa[5d19c6e4c53e5d1a]::base::codegen_crate::<rustc_codegen_llvm[2437d065f7431]::LlvmCodegenBackend>
  50:     0x7ff80d2e6c3f - <rustc_codegen_llvm[2437d065f7431]::LlvmCodegenBackend as rustc_codegen_ssa[5d19c6e4c53e5d1a]::traits::backend::CodegenBackend>::codegen_crate
  51:     0x7ff80d63ad22 - <rustc_session[76460c32d01a7a92]::session::Session>::time::<alloc[b36931eabff6d458]::boxed::Box<dyn core[eac01cc03d7c90b2]::any::Any>, rustc_interface[6d526cf79e1d2a3f]::passes::start_codegen::{closure#0}>
  52:     0x7ff80d63a87b - rustc_interface[6d526cf79e1d2a3f]::passes::start_codegen
  53:     0x7ff80d63509a - <rustc_middle[7d6c6611b495d02e]::ty::context::GlobalCtxt>::enter::<<rustc_interface[6d526cf79e1d2a3f]::queries::Queries>::ongoing_codegen::{closure#0}, core[eac01cc03d7c90b2]::result::Result<alloc[b36931eabff6d458]::boxed::Box<dyn core[eac01cc03d7c90b2]::any::Any>, rustc_span[a848110e357b7e8b]::ErrorGuaranteed>>
  54:     0x7ff80d633f4d - rustc_span[a848110e357b7e8b]::set_source_map::<core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>, rustc_interface[6d526cf79e1d2a3f]::interface::run_compiler<core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>, rustc_driver_impl[3b155c69176e0130]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  55:     0x7ff80d62e180 - std[9021ab7eb1800470]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6d526cf79e1d2a3f]::util::run_in_thread_with_globals<rustc_interface[6d526cf79e1d2a3f]::interface::run_compiler<core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>, rustc_driver_impl[3b155c69176e0130]::run_compiler::{closure#1}>::{closure#0}, core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>>
  56:     0x7ff80d95758e - <<std[9021ab7eb1800470]::thread::Builder>::spawn_unchecked_<rustc_interface[6d526cf79e1d2a3f]::util::run_in_thread_with_globals<rustc_interface[6d526cf79e1d2a3f]::interface::run_compiler<core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>, rustc_driver_impl[3b155c69176e0130]::run_compiler::{closure#1}>::{closure#0}, core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[eac01cc03d7c90b2]::result::Result<(), rustc_span[a848110e357b7e8b]::ErrorGuaranteed>>::{closure#1} as core[eac01cc03d7c90b2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7ff80af72395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h002abea1d29efb77
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/alloc/src/boxed.rs:2007:9
  58:     0x7ff80af72395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha19d8c26cc20d38b
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/alloc/src/boxed.rs:2007:9
  59:     0x7ff80af72395 - std::sys::unix::thread::Thread::new::thread_start::h6dc2d5714dd5ad65
                               at /rustc/8ce4540bd6fe7d58d4bc05f1b137d61937d3cf72/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7ff80ad129eb - <unknown>
  61:     0x7ff80ad967cc - <unknown>
  62:                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 attach the file at `/tmp/rustc-ice-2023-09-30T16:58:02.848316288Z-1802240.txt` to your bug report

note: compiler flags: -Z mir-opt-level=0 -Z mir-enable-passes=+Inline

query stack during panic:
#0 [mir_inliner_callees] computing all local function calls in `main::{closure#0}`
#1 [mir_callgraph_reachable] computing if `main::{closure#0}` (transitively) calls `main`
#2 [optimized_mir] optimizing MIR for `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@saethlin saethlin added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining labels Sep 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 30, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 30, 2023
@matthiaskrgr
Copy link
Member

Hmm, is it worthwhile fuzzing standalone mir passes or do we have dependencies between them?

@saethlin saethlin self-assigned this Sep 30, 2023
@saethlin
Copy link
Member Author

They should work independently, but the problem here isn't that one pass is relying on another to be run.

@saethlin
Copy link
Member Author

Fixing this is blocked by #116294 because I can't create a stable test for this problem with that bug.

@cjgillot
Copy link
Contributor

Marking as fixed by #116896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants