Skip to content

Compiler Error when using Allocator API for Box with const generic allocator. #89682

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
CasperN opened this issue Oct 8, 2021 · 3 comments
Closed
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CasperN
Copy link

CasperN commented Oct 8, 2021

Code

#![feature(allocator_api)]

use core::alloc::{AllocError, Allocator, Layout};
use core::ptr::NonNull;

struct AwfulAllocator<const N: usize>([u64; N]);

unsafe impl<const N: usize> Allocator for AwfulAllocator<N> {
    fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        todo!()
    }
    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
        todo!()
    }
}

fn main() {
    let f = AwfulAllocator([0; 128]);
    let _x = Box::<i32, AwfulAllocator<128>>::new_in(43, f);
}

Meta

rustc --version --verbose:

rustc --version --verbose
rustc 1.57.0-nightly (25ec82738 2021-10-05)
binary: rustc
commit-hash: 25ec8273855fde2d72ae877b397e054de5300e10
commit-date: 2021-10-05
host: x86_64-apple-darwin
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: /rustc/25ec8273855fde2d72ae877b397e054de5300e10/compiler/rustc_codegen_ssa/src/mir/operand.rs:132:38: Deref of by-Ref operand OperandRef(Ref((%"alloc::boxed::Box<core::mem::maybe_uninit::MaybeUninit<i32>, AwfulAllocator<128_usize>>"*:  %10 = alloca %"alloc::boxed::Box<core::mem::maybe_uninit::MaybeUninit<i32>, AwfulAllocator<128_usize>>", align 8), None, Align { pow2: 3 }) @ TyAndLayout { ty: std::boxed::Box<std::mem::MaybeUninit<i32>, AwfulAllocator<128_usize>>, layout: Layout { fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 8 }], memory_index: [0, 1] }, variants: Single { index: 0 }, abi: Aggregate { sized: true }, largest_niche: Some(Niche { offset: Size { raw: 0 }, scalar: Scalar { value: Pointer, valid_range: 1..=18446744073709551615 } }), align: AbiAndPrefAlign { abi: Align { pow2: 3 }, pref: Align { pow2: 3 } }, size: Size { raw: 1032 } } })
thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:1146:9 stack backtrace: 0: std::panicking::begin_panic 1: std::panic::panic_any 2: rustc_errors::HandlerInner::bug 3: rustc_errors::Handler::bug 4: rustc_middle::ty::context::tls::with_opt 5: rustc_middle::util::bug::opt_span_bug_fmt 6: rustc_middle::util::bug::bug_fmt 7: rustc_codegen_ssa::mir::operand::OperandRef::deref 8: rustc_codegen_ssa::mir::place::>::codegen_place 9: rustc_codegen_ssa::mir::rvalue::>::codegen_rvalue_operand 10: rustc_codegen_ssa::mir::codegen_mir 11: rustc_codegen_ssa::base::codegen_instance 12: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen 13: rustc_query_system::dep_graph::graph::DepGraph::with_task 14: rustc_codegen_llvm::base::compile_codegen_unit 15: rustc_codegen_ssa::base::codegen_crate 16: ::codegen_crate 17: rustc_session::utils::::time 18: rustc_interface::queries::Queries::ongoing_codegen 19: rustc_interface::queries::::enter 20: rustc_span::with_source_map 21: scoped_tls::ScopedKey::set 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.57.0-nightly (25ec827 2021-10-05) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
end of query stack
error: could not compile s

<backtrace>


Note that this does not happen if you substitute the last line with

let _x = Vec::<i32, AwfulAllocator<128>>::new_in(f);  
@CasperN CasperN 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 Oct 8, 2021
@CasperN
Copy link
Author

CasperN commented Oct 8, 2021

Reference to ZST is broken too.

Code

#![feature(allocator_api)]
use core::alloc::{AllocError, Allocator, Layout};
use core::ptr::NonNull;

struct ZST;
unsafe impl Allocator for &ZST {
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        todo!()
    }
    unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
        todo!()
    }
}
fn main() {
        let _ = Box::<i32, &ZST>::new_in(43, &ZST);
}

@Alexendoo
Copy link
Member

The reference ICE is fixed (#94043), original still ICEs

@Alexendoo
Copy link
Member

Original is fixed by #94414

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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) ❄️ 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

3 participants