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: 'tls access is checked in `Rvalue::ThreadLocalRef', compiler/rustc_mir/src/transform/check_consts/validation.rs:359:9 #85768

Closed
chengniansun opened this issue May 28, 2021 · 1 comment · Fixed by #85880
Labels
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

@chengniansun
Copy link

Code

#![feature(thread_local)]
#[thread_local]
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
const fn g(x: &mut [u32; 8]) {
    std::mem::swap(x, &mut STATIC_VAR_2)
}

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (9111b8ae9 2021-05-26)
binary: rustc
commit-hash: 9111b8ae9793f18179a1336417618fc07a9cac85
commit-date: 2021-05-26
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1

Error output

error[E0658]: mutable references are not allowed in constant functions
 --> mutant.rs:4:12
  |
4 | const fn g(x: &mut [u32; 8]) {
  |            ^
  |
  = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
  = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable

error[E0625]: thread-local statics cannot be accessed at compile-time
 --> mutant.rs:5:28
  |
5 |     std::mem::swap(x, &mut STATIC_VAR_2)
  |                            ^^^^^^^^^^^^

thread 'rustc' panicked at 'tls access is checked in `Rvalue::ThreadLocalRef', compiler/rustc_mir/src/transform/check_consts/validation.rs:359:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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: rustc 1.54.0-nightly (9111b8ae9 2021-05-26) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [mir_const_qualif] const checking `g`
#1 [mir_promoted] processing `g`
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Backtrace

error[E0658]: mutable references are not allowed in constant functions
 --> mutant.rs:4:12
  |
4 | const fn g(x: &mut [u32; 8]) {
  |            ^
  |
  = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
  = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable

error[E0625]: thread-local statics cannot be accessed at compile-time
 --> mutant.rs:5:28
  |
5 |     std::mem::swap(x, &mut STATIC_VAR_2)
  |                            ^^^^^^^^^^^^

thread 'rustc' panicked at 'tls access is checked in `Rvalue::ThreadLocalRef', compiler/rustc_mir/src/transform/check_consts/validation.rs:359:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_mir::transform::check_consts::validation::Validator::check_static
   2: <rustc_mir::transform::check_consts::validation::Validator as rustc_middle::mir::visit::Visitor>::visit_rvalue
   3: <rustc_mir::transform::check_consts::validation::Validator as rustc_middle::mir::visit::Visitor>::visit_statement
   4: rustc_mir::transform::check_consts::validation::Validator::check_body
   5: rustc_mir::transform::mir_const_qualif
   6: core::ops::function::FnOnce::call_once
   7: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
   8: rustc_data_structures::stack::ensure_sufficient_stack
   9: rustc_query_system::query::plumbing::force_query_with_job
  10: rustc_query_system::query::plumbing::get_query_impl
  11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const_qualif
  12: rustc_mir::transform::mir_promoted
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  14: rustc_data_structures::stack::ensure_sufficient_stack
  15: rustc_query_system::query::plumbing::force_query_with_job
  16: rustc_query_system::query::plumbing::get_query_impl
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  18: rustc_mir::borrow_check::mir_borrowck
  19: core::ops::function::FnOnce::call_once
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::force_query_with_job
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  25: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  26: rustc_interface::passes::analysis
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  28: rustc_data_structures::stack::ensure_sufficient_stack
  29: rustc_query_system::query::plumbing::force_query_with_job
  30: rustc_query_system::query::plumbing::get_query_impl
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  32: rustc_interface::passes::QueryContext::enter
  33: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: 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: rustc 1.54.0-nightly (9111b8ae9 2021-05-26) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [mir_const_qualif] const checking `g`
#1 [mir_promoted] processing `g`
#2 [mir_borrowck] borrow-checking `g`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

@chengniansun chengniansun added 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. labels May 28, 2021
@LingMan
Copy link
Contributor

LingMan commented May 29, 2021

The failing assert is:

assert!(
!self.tcx.is_thread_local_static(def_id),
"tls access is checked in `Rvalue::ThreadLocalRef"
);

Trying to bisect leads me all the way back to 2020-06-02, but that's just the day the assert was added in the first place (#71192). Had to add #![feature(const_fn)] somewhere in late September 2020 though.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 3, 2021
convert assertion on rvalue::threadlocalref to delay bug

Closes rust-lang#85768
r? `@oli-obk`
@bors bors closed this as completed in 0d4bbc5 Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

2 participants