Skip to content

ICE when using Box<T, A> with non-zero sized A #78459

Closed
@exrook

Description

@exrook

While working on #77438, I've run into the following ICE. It seems to be caused by the type layout code not expecting Box to have more than 3 fields, in this case the fat pointer containing two fields, plus the AllocRef instance. On further consideration, the issue also appears with Box<T, A> as long as A is non zero sized.

This ICE was likely not encountered during testing of #77187 because in the case of Box<T, Global>, Global is zero sized. In the example below, removing the borrow of Global will cause the compilation to succeed.

@eddyb could you take a look at this? :)

cc @TimDiekmann you may run into this as well on RawVec

Code

Old code

Playground link

#![feature(allocator_api)]

fn main() {
    Box::new_in(&[0, 1], &std::alloc::Global);
}

New, more minimal code

Playground link

#![feature(allocator_api)]

fn main() {
    Box::new_in((), &std::alloc::Global);
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (fd542592f 2020-10-26) running on x86_64-unknown-linux-gnu - playground
rustc 1.48.0-beta.3 (4708ac76e 2020-10-15) running on x86_64-unknown-linux-gnu - local dev environment

Error output

assert!(i < this.fields.count());

thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/fd542592f08ca0d1f7255600115c2eafdf6b5da7/compiler/rustc_middle/src/ty/layout.rs:2056:17
Backtrace

From playground

thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/fd542592f08ca0d1f7255600115c2eafdf6b5da7/compiler/rustc_middle/src/ty/layout.rs:2056:17
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_middle::ty::layout::<impl rustc_target::abi::TyAndLayoutMethods<C> for &rustc_middle::ty::TyS>::field
   2: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
   3: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
   4: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_codegen_llvm::abi::FnAbiLlvmExt>::llvm_type
   5: rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_llvm::context::CodegenCx>::predefine_fn
   6: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   7: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
   8: rustc_codegen_llvm::base::compile_codegen_unit
   9: rustc_codegen_ssa::base::codegen_crate
  10: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  11: rustc_interface::passes::QueryContext::enter
  12: rustc_interface::queries::Queries::ongoing_codegen
  13: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  14: rustc_span::with_source_map
  15: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsA-layoutArea: Memory layout of typesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions