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: unable to turn pointer into raw bytes #72113

Closed
DutchGhost opened this issue May 11, 2020 · 2 comments
Closed

ICE: unable to turn pointer into raw bytes #72113

DutchGhost opened this issue May 11, 2020 · 2 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

Code

#![feature(const_raw_ptr_deref)]

mod internal {
    static UNIT: &'static () = &();

    static OTHER_UNIT: &'static u8 = unsafe { &*(&self::UNIT as *const _ as *const u8) };
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (9912925c2 2020-05-10)

Error output

error: internal compiler error: src/librustc_mir/interpret/validity.rs:867: Unexpected error during validation: unable to turn pointer into raw bytes
Backtrace

   Compiling playground v0.0.1 (/playground)
warning: static is never used: `UNIT`
 --> src/main.rs:4:5
  |
4 |     static UNIT: &'static () = &();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: static is never used: `OTHER_UNIT`
 --> src/main.rs:6:5
  |
6 |     static OTHER_UNIT: &'static u8 = unsafe { &*(&self::UNIT as *const _ as *const u8) };
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: src/librustc_mir/interpret/validity.rs:867: Unexpected error during validation: unable to turn pointer into raw bytes

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc_middle::ty::context::tls::with_opt::{{closure}}
  17: rustc_middle::ty::context::tls::with_opt
  18: rustc_middle::util::bug::opt_span_bug_fmt
  19: rustc_middle::util::bug::bug_fmt
  20: rustc_mir::interpret::validity::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::validate_operand_internal
  21: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  27: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::get_query_impl
  31: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  32: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_poly
  33: <rustc_lint::BuiltinCombinedLateLintPass as rustc_lint::passes::LateLintPass>::check_item
  34: rustc_hir::intravisit::Visitor::visit_nested_item
  35: rustc_hir::intravisit::walk_item
  36: rustc_hir::intravisit::Visitor::visit_nested_item
  37: rustc_hir::intravisit::walk_crate
  38: rustc_session::utils::<impl rustc_session::session::Session>::time
  39: rustc_session::utils::<impl rustc_session::session::Session>::time
  40: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  41: rustc_session::utils::<impl rustc_session::session::Session>::time
  42: rustc_interface::passes::analysis
  43: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::get_query_impl
  47: rustc_middle::ty::context::tls::enter_global
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: scoped_tls::ScopedKey<T>::set
  50: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-nightly (9912925c2 2020-05-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [const_eval_validated] const-evaluating + checking `internal::OTHER_UNIT`
#1 [const_eval_validated] const-evaluating + checking `internal::OTHER_UNIT`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 2 warnings emitted

error: could not compile `playground`.

@DutchGhost DutchGhost 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 11, 2020
@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) requires-nightly This issue requires a nightly compiler in some way. labels May 11, 2020
@hellow554
Copy link
Contributor

hellow554 commented May 12, 2020

Little bit shorter:

#![feature(const_raw_ptr_deref)]

const OTHER_UNIT: &'static u8 = unsafe { &*(&&() as *const _ as *const u8) };

fn main() {}

const or static doesn't matter, if inside main or outside, doesn't matter. Just writing &() doesn't ICE:

error: any use of this value will cause an error
 --> src/main.rs:3:42
  |
3 | const OTHER_UNIT: &'static u8 = unsafe { &*(&() as *const _ as *const u8) };
  | -----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
  |                                          |
  |                                          memory access failed: pointer must be in-bounds at offset 1, but is outside bounds of alloc2 which has size 0
  |
  = note: `#[deny(const_err)]` on by default

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 18, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Nov 5, 2020

This has been fixed and either works (in case of the original example, the error is delayed until an actual use happens), or it errors (in case constants are involved)

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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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

5 participants