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

ICE: interpret const eval failure of Unevaluated(UnevaluatedConst #125476

Closed
matthiaskrgr opened this issue May 24, 2024 · 4 comments · Fixed by #133704
Closed

ICE: interpret const eval failure of Unevaluated(UnevaluatedConst #125476

matthiaskrgr opened this issue May 24, 2024 · 4 comments · Fixed by #133704
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented May 24, 2024

latest manually reduced form:

pub struct Data([u8; usize::MAX >> 2]);
const _: &'static [Data] = &[];

auto-reduced (treereduce-rust):

pub struct Data([[[u32; 9999999]; 777777777]; 5_i32]);
const _: &'static Data = unsafe { &*(&[] as *const Data) };

original:

pub struct Data([[[u32; 9999999]; 777777777]; 5_i32]);
const _: &'static Data = unsafe { &*(&[] as *const Data) };

pub fn main() {}

Version information

rustc 1.80.0-nightly (78dd504f2 2024-05-24)
binary: rustc
commit-hash: 78dd504f2fd87c0cfabff7d9174253411caf2f80
commit-date: 2024-05-24
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Command:
/home/gh-matthiaskrgr/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.QyRvEWiVipgV/rustc_testrunner_tmpdir_reporting.6eRld1crLCV1/mvce.rs:2:60
  |
2 | const _: &'static Data = unsafe { &*(&[] as *const Data) };
  |                                                            ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.QyRvEWiVipgV/rustc_testrunner_tmpdir_reporting.6eRld1crLCV1/mvce.rs`

error[E0080]: evaluation of constant value failed
 --> /tmp/icemaker_global_tempdir.QyRvEWiVipgV/rustc_testrunner_tmpdir_reporting.6eRld1crLCV1/mvce.rs:2:39
  |
2 | const _: &'static Data = unsafe { &*(&[] as *const Data) };
  |                                       ^^ values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:1195:33: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:9 ~ mvce[c32c]::_), args: [], promoted: Some(promoted[0]) }, &'{erased} [Data; 0_usize]) which is not in required_consts
 --> /tmp/icemaker_global_tempdir.QyRvEWiVipgV/rustc_testrunner_tmpdir_reporting.6eRld1crLCV1/mvce.rs:2:38
  |
2 | const _: &'static Data = unsafe { &*(&[] as *const Data) };
  |                                      ^^^

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:1195:33:
Box<dyn Any>
stack backtrace:
   0:     0x7f43c6f8ca25 - std::backtrace_rs::backtrace::libunwind::trace::h8966c752ee3e4366
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f43c6f8ca25 - std::backtrace_rs::backtrace::trace_unsynchronized::h9ea5b98770d1aa33
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f43c6f8ca25 - std::sys_common::backtrace::_print_fmt::he48619da8989a3bf
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f43c6f8ca25 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h396d8ace60c94a52
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f43c6fdbafb - core::fmt::rt::Argument::fmt::h5a43b7685e1a8d8c
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/core/src/fmt/rt.rs:165:63
   5:     0x7f43c6fdbafb - core::fmt::write::hb0f90054e0ddacf7
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/core/src/fmt/mod.rs:1172:21
   6:     0x7f43c6f8177f - std::io::Write::write_fmt::hd596e75ff8fa0846
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/io/mod.rs:1835:15
   7:     0x7f43c6f8c7fe - std::sys_common::backtrace::_print::h40262024fa5f287e
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f43c6f8c7fe - std::sys_common::backtrace::print::ha7fcd41b8add839e
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f43c6f8f229 - std::panicking::default_hook::{{closure}}::h60e0c4e988d17123
  10:     0x7f43c6f8efca - std::panicking::default_hook::h9ed993c933fab0c2
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/panicking.rs:298:9
  11:     0x7f43ca114110 - std[4869c667286d786e]::panicking::update_hook::<alloc[803fe285b37d8cd0]::boxed::Box<rustc_driver_impl[957f6692bf6a3a58]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f43c6f8f95b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hefe0f5c02c622009
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/alloc/src/boxed.rs:2077:9
  13:     0x7f43c6f8f95b - std::panicking::rust_panic_with_hook::h4ddf3c210c6e33af
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/panicking.rs:799:13
  14:     0x7f43ca1448d4 - std[4869c667286d786e]::panicking::begin_panic::<rustc_errors[9393b57c1e89acaf]::ExplicitBug>::{closure#0}
  15:     0x7f43ca1413b6 - std[4869c667286d786e]::sys_common::backtrace::__rust_end_short_backtrace::<std[4869c667286d786e]::panicking::begin_panic<rustc_errors[9393b57c1e89acaf]::ExplicitBug>::{closure#0}, !>
  16:     0x7f43ca13c756 - std[4869c667286d786e]::panicking::begin_panic::<rustc_errors[9393b57c1e89acaf]::ExplicitBug>
  17:     0x7f43ca14dd11 - <rustc_errors[9393b57c1e89acaf]::diagnostic::BugAbort as rustc_errors[9393b57c1e89acaf]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f43ca071d78 - <rustc_errors[9393b57c1e89acaf]::DiagCtxt>::span_bug::<rustc_span[6eac4943cc7cd1a3]::span_encoding::Span, alloc[803fe285b37d8cd0]::string::String>
  19:     0x7f43ca0923fd - rustc_middle[34114187831b2967]::util::bug::opt_span_bug_fmt::<rustc_span[6eac4943cc7cd1a3]::span_encoding::Span>::{closure#0}
  20:     0x7f43ca09264a - rustc_middle[34114187831b2967]::ty::context::tls::with_opt::<rustc_middle[34114187831b2967]::util::bug::opt_span_bug_fmt<rustc_span[6eac4943cc7cd1a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f43ca087d6b - rustc_middle[34114187831b2967]::ty::context::tls::with_context_opt::<rustc_middle[34114187831b2967]::ty::context::tls::with_opt<rustc_middle[34114187831b2967]::util::bug::opt_span_bug_fmt<rustc_span[6eac4943cc7cd1a3]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f43c8c759a7 - rustc_middle[34114187831b2967]::util::bug::span_bug_fmt::<rustc_span[6eac4943cc7cd1a3]::span_encoding::Span>
  23:     0x7f43c9584bfe - <rustc_const_eval[2a16a84a09f3f441]::interpret::eval_context::InterpCx<rustc_const_eval[2a16a84a09f3f441]::const_eval::machine::CompileTimeInterpreter>>::eval_rvalue_into_place
  24:     0x7f43c950408c - rustc_const_eval[2a16a84a09f3f441]::const_eval::eval_queries::eval_to_allocation_raw_provider
  25:     0x7f43cbafa076 - rustc_query_impl[2cb4a958aeb3f22c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2cb4a958aeb3f22c]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 24usize]>>
  26:     0x7f43cbaf9899 - rustc_query_system[5af415981e64bee5]::query::plumbing::try_execute_query::<rustc_query_impl[2cb4a958aeb3f22c]::DynamicConfig<rustc_query_system[5af415981e64bee5]::query::caches::DefaultCache<rustc_middle[34114187831b2967]::ty::ParamEnvAnd<rustc_middle[34114187831b2967]::mir::interpret::GlobalId>, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[2cb4a958aeb3f22c]::plumbing::QueryCtxt, false>
  27:     0x7f43cbaf9470 - rustc_query_impl[2cb4a958aeb3f22c]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f43cbaf8ff6 - rustc_middle[34114187831b2967]::query::plumbing::query_get_at::<rustc_query_system[5af415981e64bee5]::query::caches::DefaultCache<rustc_middle[34114187831b2967]::ty::ParamEnvAnd<rustc_middle[34114187831b2967]::mir::interpret::GlobalId>, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 24usize]>>>
  29:     0x7f43cbaf747c - rustc_const_eval[2a16a84a09f3f441]::const_eval::eval_queries::eval_to_const_value_raw_provider
  30:     0x7f43cbaf73f6 - rustc_query_impl[2cb4a958aeb3f22c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2cb4a958aeb3f22c]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 24usize]>>
  31:     0x7f43cbaf985c - rustc_query_system[5af415981e64bee5]::query::plumbing::try_execute_query::<rustc_query_impl[2cb4a958aeb3f22c]::DynamicConfig<rustc_query_system[5af415981e64bee5]::query::caches::DefaultCache<rustc_middle[34114187831b2967]::ty::ParamEnvAnd<rustc_middle[34114187831b2967]::mir::interpret::GlobalId>, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[2cb4a958aeb3f22c]::plumbing::QueryCtxt, false>
  32:     0x7f43cbaf9370 - rustc_query_impl[2cb4a958aeb3f22c]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7f43cb754bdf - <rustc_middle[34114187831b2967]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[513396f821121b45]::check_crate::{closure#3}>::{closure#0}
  34:     0x7f43cb753022 - rustc_hir_analysis[513396f821121b45]::check_crate
  35:     0x7f43cb73323e - rustc_interface[6c4077a70579b4d0]::passes::analysis
  36:     0x7f43cb732d95 - rustc_query_impl[2cb4a958aeb3f22c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2cb4a958aeb3f22c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7f43cc13a8a5 - rustc_query_system[5af415981e64bee5]::query::plumbing::try_execute_query::<rustc_query_impl[2cb4a958aeb3f22c]::DynamicConfig<rustc_query_system[5af415981e64bee5]::query::caches::SingleCache<rustc_middle[34114187831b2967]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2cb4a958aeb3f22c]::plumbing::QueryCtxt, false>
  38:     0x7f43cc13a60f - rustc_query_impl[2cb4a958aeb3f22c]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f43cbfb908e - rustc_interface[6c4077a70579b4d0]::interface::run_compiler::<core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>, rustc_driver_impl[957f6692bf6a3a58]::run_compiler::{closure#0}>::{closure#1}
  40:     0x7f43cbfa4927 - std[4869c667286d786e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6c4077a70579b4d0]::util::run_in_thread_with_globals<rustc_interface[6c4077a70579b4d0]::util::run_in_thread_pool_with_globals<rustc_interface[6c4077a70579b4d0]::interface::run_compiler<core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>, rustc_driver_impl[957f6692bf6a3a58]::run_compiler::{closure#0}>::{closure#1}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>::{closure#0}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>
  41:     0x7f43cbfa46ea - <<std[4869c667286d786e]::thread::Builder>::spawn_unchecked_<rustc_interface[6c4077a70579b4d0]::util::run_in_thread_with_globals<rustc_interface[6c4077a70579b4d0]::util::run_in_thread_pool_with_globals<rustc_interface[6c4077a70579b4d0]::interface::run_compiler<core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>, rustc_driver_impl[957f6692bf6a3a58]::run_compiler::{closure#0}>::{closure#1}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>::{closure#0}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cb4e43784437d8f1]::result::Result<(), rustc_span[6eac4943cc7cd1a3]::ErrorGuaranteed>>::{closure#2} as core[cb4e43784437d8f1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f43c6f9973b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h496e4fc5fb53ece2
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/alloc/src/boxed.rs:2063:9
  43:     0x7f43c6f9973b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd4fa5d81a55c123f
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/alloc/src/boxed.rs:2063:9
  44:     0x7f43c6f9973b - std::sys::pal::unix::thread::Thread::new::thread_start::h04d31b4f40ca136c
                               at /rustc/78dd504f2fd87c0cfabff7d9174253411caf2f80/library/std/src/sys/pal/unix/thread.rs:108:17
  45:     0x7f43c6c94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  46:     0x7f43c6d26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  47:                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.80.0-nightly (78dd504f2 2024-05-24) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `_`
#1 [eval_to_const_value_raw] simplifying constant for the type system `_`
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0080, E0601.
For more information about an error, try `rustc --explain E0080`.

@matthiaskrgr matthiaskrgr 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. labels May 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 24, 2024
@workingjubilee
Copy link
Member

Reduces further:

pub struct Data([u8; usize::MAX >> 16]);
const _: &'static Data = unsafe { &*(&[] as *const Data) };

@workingjubilee
Copy link
Member

Further:

pub struct Data([u8; usize::MAX >> 16]);
const _: &'static [Data] = &[];

The slice construction is what matters it seems, this doesn't trigger it:

pub struct Data([u8; usize::MAX >> 16]);
const _: &'static Data = &Data([0; usize::MAX >> 16]);

@matthiaskrgr matthiaskrgr added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels May 24, 2024
@oli-obk
Copy link
Contributor

oli-obk commented May 24, 2024

This looks suspiciously like what Ralf hinted at in #124516 (comment)

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 25, 2024
@oli-obk oli-obk moved this to Todo in error tainting May 25, 2024
@oli-obk oli-obk removed this from error tainting May 25, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Sep 17, 2024
@RalfJung
Copy link
Member

RalfJung commented Dec 1, 2024

This looks suspiciously like what Ralf hinted at in #124516 (comment)

Yeah that's exactly what this is. :) Will be fixed by #133704.
(Feel free to ping me for issues like this, I only just saw this or else I would have fixed it long ago.)

@bors bors closed this as completed in b1a643e Dec 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Rollup merge of rust-lang#133704 - RalfJung:promoted-size-overflow-ice, r=compiler-errors

fix ICE when promoted has layout size overflow

Turns out there is no reason to distinguish `tainted_by_errors` and `can_be_spurious` here, we can just track whether we allow this even in "infallible" constants.

Fixes rust-lang#125476
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Dec 4, 2024
…iler-errors

fix ICE when promoted has layout size overflow

Turns out there is no reason to distinguish `tainted_by_errors` and `can_be_spurious` here, we can just track whether we allow this even in "infallible" constants.

Fixes rust-lang/rust#125476
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Dec 11, 2024
…iler-errors

fix ICE when promoted has layout size overflow

Turns out there is no reason to distinguish `tainted_by_errors` and `can_be_spurious` here, we can just track whether we allow this even in "infallible" constants.

Fixes rust-lang/rust#125476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants