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: primitive read not possible for type: AlignedUsize #104631

Closed
matthiaskrgr opened this issue Nov 20, 2022 · 4 comments
Closed

ICE: primitive read not possible for type: AlignedUsize #104631

matthiaskrgr opened this issue Nov 20, 2022 · 4 comments
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

Code

src/test/ui/dyn-star/align.rs

//[normal] check-pass

#![feature(dyn_star)]
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes

use std::fmt::Debug;

#[cfg_attr(over_aligned,      repr(C, align(1024)))]
#[cfg_attr(not(over_aligned), repr(C))]
#[derive(Debug)]
struct AlignedUsize(usize);

fn main() {
    let x = AlignedUsize(12) as dyn* Debug;
    //[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type
}

Meta

rustc --version --verbose:

<version>

Error output

warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/test/ui/dyn-star/align.rs:4:12
  |
4 | #![feature(dyn_star)]
  |            ^^^^^^^^
  |
  = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unused variable: `x`
  --> src/test/ui/dyn-star/align.rs:15:9
   |
15 |     let x = AlignedUsize(12) as dyn* Debug;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default
Backtrace


error: internal compiler error: /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/compiler/rustc_const_eval/src/interpret/operand.rs:391:13: primitive read not possible for type: AlignedUsize
  --> src/test/ui/dyn-star/align.rs:15:13
   |
15 |     let x = AlignedUsize(12) as dyn* Debug;
   |             ^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/compiler/rustc_errors/src/lib.rs:969:33
stack backtrace:
   0:     0x7fb1de566a50 - std::backtrace_rs::backtrace::libunwind::trace::hc67583789182810a
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb1de566a50 - std::backtrace_rs::backtrace::trace_unsynchronized::h1938dfa1aa97f8ae
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb1de566a50 - std::sys_common::backtrace::_print_fmt::hc27f3d4fb7d08e50
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fb1de566a50 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0efab7bfe941d4d0
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fb1da5c863e - core::fmt::write::h816cc3b1bcaa0f63
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/core/src/fmt/mod.rs:1208:17
   5:     0x7fb1de55ab25 - std::io::Write::write_fmt::h33dba8a681e64ab5
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/io/mod.rs:1682:15
   6:     0x7fb1de566815 - std::sys_common::backtrace::_print::ha3a4aa724c6dd991
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fb1de566815 - std::sys_common::backtrace::print::h871c005525ccf4a5
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fb1de568b2f - std::panicking::default_hook::{{closure}}::h424788f485e3b8e1
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/panicking.rs:267:22
   9:     0x7fb1de56886a - std::panicking::default_hook::ha4cff4743b1eccf9
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/panicking.rs:286:9
  10:     0x7fb1dd7c53c4 - <rustc_driver[31383bd51e4ce3bf]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[521a141dd0e2ec56]::ops::function::FnOnce<(&core[521a141dd0e2ec56]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7fb1de56931d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hafd0e2079dea2b50
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/alloc/src/boxed.rs:2032:9
  12:     0x7fb1de56931d - std::panicking::rust_panic_with_hook::hc5412f99bf75d7f4
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/panicking.rs:692:13
  13:     0x7fb1dde39f11 - std[cb58addc38ea5d7f]::panicking::begin_panic::<rustc_errors[268b7194fd18b781]::ExplicitBug>::{closure#0}
  14:     0x7fb1dde38de6 - std[cb58addc38ea5d7f]::sys_common::backtrace::__rust_end_short_backtrace::<std[cb58addc38ea5d7f]::panicking::begin_panic<rustc_errors[268b7194fd18b781]::ExplicitBug>::{closure#0}, !>
  15:     0x7fb1ddd9d0c6 - std[cb58addc38ea5d7f]::panicking::begin_panic::<rustc_errors[268b7194fd18b781]::ExplicitBug>
  16:     0x7fb1dde38976 - std[cb58addc38ea5d7f]::panic::panic_any::<rustc_errors[268b7194fd18b781]::ExplicitBug>
  17:     0x7fb1dde33cf0 - <rustc_errors[268b7194fd18b781]::HandlerInner>::span_bug::<rustc_span[4526806d7c1f36b2]::span_encoding::Span, &alloc[3463f07d9a1225bb]::string::String>
  18:     0x7fb1dde31a77 - <rustc_errors[268b7194fd18b781]::Handler>::span_bug::<rustc_span[4526806d7c1f36b2]::span_encoding::Span, &alloc[3463f07d9a1225bb]::string::String>
  19:     0x7fb1dddd9908 - rustc_middle[3045a148646aecd0]::ty::context::tls::with_context_opt::<rustc_middle[3045a148646aecd0]::ty::context::tls::with_opt<rustc_middle[3045a148646aecd0]::util::bug::opt_span_bug_fmt<rustc_span[4526806d7c1f36b2]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  20:     0x7fb1dddd97a6 - rustc_middle[3045a148646aecd0]::util::bug::opt_span_bug_fmt::<rustc_span[4526806d7c1f36b2]::span_encoding::Span>
  21:     0x7fb1dc904a24 - rustc_middle[3045a148646aecd0]::util::bug::span_bug_fmt::<rustc_span[4526806d7c1f36b2]::span_encoding::Span>
  22:     0x7fb1dc8daa99 - <rustc_const_eval[51ebc319a3c288fc]::interpret::eval_context::InterpCx<rustc_mir_transform[1c913e9f9ba10abc]::const_prop::ConstPropMachine>>::eval_rvalue_into_place
  23:     0x7fb1dbf8d4b7 - <rustc_mir_transform[1c913e9f9ba10abc]::const_prop_lint::ConstPropagator as rustc_middle[3045a148646aecd0]::mir::visit::Visitor>::visit_body
  24:     0x7fb1dbf83d2a - <rustc_mir_transform[1c913e9f9ba10abc]::const_prop_lint::ConstProp as rustc_mir_transform[1c913e9f9ba10abc]::pass_manager::MirLint>::run_lint
  25:     0x7fb1db9f53a3 - rustc_mir_transform[1c913e9f9ba10abc]::run_analysis_to_runtime_passes
  26:     0x7fb1db9f3e54 - rustc_mir_transform[1c913e9f9ba10abc]::mir_drops_elaborated_and_const_checked
  27:     0x7fb1dc63f8a9 - rustc_query_system[fc3aa43ff1e3f72f]::query::plumbing::try_execute_query::<rustc_query_impl[a10e1632aef79c39]::plumbing::QueryCtxt, rustc_query_system[fc3aa43ff1e3f72f]::query::caches::DefaultCache<rustc_middle[3045a148646aecd0]::ty::WithOptConstParam<rustc_span[4526806d7c1f36b2]::def_id::LocalDefId>, &rustc_data_structures[9e70e8f4e8382b0d]::steal::Steal<rustc_middle[3045a148646aecd0]::mir::Body>>>
  28:     0x7fb1dc0f8a13 - rustc_mir_transform[1c913e9f9ba10abc]::optimized_mir
  29:     0x7fb1dc0f4553 - rustc_query_system[fc3aa43ff1e3f72f]::query::plumbing::try_execute_query::<rustc_query_impl[a10e1632aef79c39]::plumbing::QueryCtxt, rustc_query_system[fc3aa43ff1e3f72f]::query::caches::DefaultCache<rustc_span[4526806d7c1f36b2]::def_id::DefId, &rustc_middle[3045a148646aecd0]::mir::Body>>
  30:     0x7fb1dc3281d3 - <rustc_middle[3045a148646aecd0]::ty::context::TyCtxt>::instance_mir
  31:     0x7fb1dc31937b - rustc_monomorphize[542e48549e1eab61]::collector::collect_neighbours
  32:     0x7fb1dc316773 - rustc_monomorphize[542e48549e1eab61]::collector::collect_items_rec
  33:     0x7fb1dcc34e6c - <rustc_session[883587d705af57a8]::session::Session>::time::<(), rustc_monomorphize[542e48549e1eab61]::collector::collect_crate_mono_items::{closure#1}>
  34:     0x7fb1dcc34969 - rustc_monomorphize[542e48549e1eab61]::collector::collect_crate_mono_items
  35:     0x7fb1dcc33ca3 - rustc_monomorphize[542e48549e1eab61]::partitioning::collect_and_partition_mono_items
  36:     0x7fb1dcf83870 - rustc_query_system[fc3aa43ff1e3f72f]::query::plumbing::try_execute_query::<rustc_query_impl[a10e1632aef79c39]::plumbing::QueryCtxt, rustc_query_system[fc3aa43ff1e3f72f]::query::caches::DefaultCache<(), (&std[cb58addc38ea5d7f]::collections::hash::set::HashSet<rustc_span[4526806d7c1f36b2]::def_id::DefId, core[521a141dd0e2ec56]::hash::BuildHasherDefault<rustc_hash[fdce590595b7296d]::FxHasher>>, &[rustc_middle[3045a148646aecd0]::mir::mono::CodegenUnit])>>
  37:     0x7fb1dcf8353b - rustc_query_system[fc3aa43ff1e3f72f]::query::plumbing::get_query::<rustc_query_impl[a10e1632aef79c39]::queries::collect_and_partition_mono_items, rustc_query_impl[a10e1632aef79c39]::plumbing::QueryCtxt>
  38:     0x7fb1dcf8347e - <rustc_query_impl[a10e1632aef79c39]::Queries as rustc_middle[3045a148646aecd0]::ty::query::QueryEngine>::collect_and_partition_mono_items
  39:     0x7fb1dceb5e4b - rustc_codegen_ssa[62e3ce45a5d58d5f]::base::codegen_crate::<rustc_codegen_llvm[8cc7a0b1f5c8b714]::LlvmCodegenBackend>
  40:     0x7fb1dceb5c09 - <rustc_codegen_llvm[8cc7a0b1f5c8b714]::LlvmCodegenBackend as rustc_codegen_ssa[62e3ce45a5d58d5f]::traits::backend::CodegenBackend>::codegen_crate
  41:     0x7fb1dca7fc21 - <rustc_session[883587d705af57a8]::session::Session>::time::<alloc[3463f07d9a1225bb]::boxed::Box<dyn core[521a141dd0e2ec56]::any::Any>, rustc_interface[24fa5d2953a1af2]::passes::start_codegen::{closure#0}>
  42:     0x7fb1dca7f714 - rustc_interface[24fa5d2953a1af2]::passes::start_codegen
  43:     0x7fb1dca79ac0 - <rustc_interface[24fa5d2953a1af2]::passes::QueryContext>::enter::<<rustc_interface[24fa5d2953a1af2]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[521a141dd0e2ec56]::result::Result<alloc[3463f07d9a1225bb]::boxed::Box<dyn core[521a141dd0e2ec56]::any::Any>, rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>
  44:     0x7fb1dca76ec3 - <rustc_interface[24fa5d2953a1af2]::queries::Queries>::ongoing_codegen
  45:     0x7fb1dca75fd2 - <rustc_interface[24fa5d2953a1af2]::interface::Compiler>::enter::<rustc_driver[31383bd51e4ce3bf]::run_compiler::{closure#1}::{closure#2}, core[521a141dd0e2ec56]::result::Result<core[521a141dd0e2ec56]::option::Option<rustc_interface[24fa5d2953a1af2]::queries::Linker>, rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>
  46:     0x7fb1dca70fd2 - rustc_span[4526806d7c1f36b2]::with_source_map::<core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>, rustc_interface[24fa5d2953a1af2]::interface::run_compiler<core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>, rustc_driver[31383bd51e4ce3bf]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  47:     0x7fb1dca70ac9 - <scoped_tls[cdc8eb0d557683b4]::ScopedKey<rustc_span[4526806d7c1f36b2]::SessionGlobals>>::set::<rustc_interface[24fa5d2953a1af2]::interface::run_compiler<core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>, rustc_driver[31383bd51e4ce3bf]::run_compiler::{closure#1}>::{closure#0}, core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>
  48:     0x7fb1dca700d8 - std[cb58addc38ea5d7f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[24fa5d2953a1af2]::util::run_in_thread_pool_with_globals<rustc_interface[24fa5d2953a1af2]::interface::run_compiler<core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>, rustc_driver[31383bd51e4ce3bf]::run_compiler::{closure#1}>::{closure#0}, core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>
  49:     0x7fb1dca6fdfc - <<std[cb58addc38ea5d7f]::thread::Builder>::spawn_unchecked_<rustc_interface[24fa5d2953a1af2]::util::run_in_thread_pool_with_globals<rustc_interface[24fa5d2953a1af2]::interface::run_compiler<core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>, rustc_driver[31383bd51e4ce3bf]::run_compiler::{closure#1}>::{closure#0}, core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[521a141dd0e2ec56]::result::Result<(), rustc_errors[268b7194fd18b781]::ErrorGuaranteed>>::{closure#1} as core[521a141dd0e2ec56]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7fb1de5705d3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he14419f019efa077
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/alloc/src/boxed.rs:2000:9
  51:     0x7fb1de5705d3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc04646210560e02e
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/alloc/src/boxed.rs:2000:9
  52:     0x7fb1de5705d3 - std::sys::unix::thread::Thread::new::thread_start::h9810da48ba5dc059
                               at /rustc/c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b/library/std/src/sys/unix/thread.rs:108:17
  53:     0x7fb1da3078fd - <unknown>
  54:     0x7fb1da389a60 - <unknown>
  55:                0x0 - <unknown>

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.67.0-nightly (c5d82ed7a 2022-11-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#1 [optimized_mir] optimizing MIR for `main`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error; 2 warnings emitted

@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 Nov 20, 2022
@compiler-errors compiler-errors self-assigned this Nov 21, 2022
@langston-barrett
Copy link

Were there special flags needed to get this to ICE? I can't reproduce on

rustc 1.70.0-nightly (511364e78 2023-03-16)
binary: rustc
commit-hash: 511364e7874dba9649a264100407e4bffe7b5425
commit-date: 2023-03-16
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

@compiler-errors
Copy link
Member

You need to do a full build, not just a check, so make sure it gets all the way to codegen?

@compiler-errors
Copy link
Member

Oh, nvm, you need to compile this with --cfg over_aligned.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 7, 2023
@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 10, 2023
@JohnTitor
Copy link
Member

MCVE:

#![feature(dyn_star)]
#![allow(incomplete_features)]

use std::fmt::Debug;

#[repr(C)]
#[derive(Debug)]
struct AlignedUsize(usize);

fn main() {
    let _x = AlignedUsize(12) as dyn* Debug;
}

1.70.0-nightly (696aaad 2023-04-09) now emits an error instead of ICE:

error[E0277]: `AlignedUsize` needs to have the same ABI as a pointer
  --> src/main.rs:11:14
   |
11 |     let _x = AlignedUsize(12) as dyn* Debug;
   |              ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-like type
   |
   = help: the trait `PointerLike` is not implemented for `AlignedUsize`

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

Marking as E-needs-test

JohnTitor added a commit to JohnTitor/rust that referenced this issue Apr 11, 2023
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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
5 participants