Skip to content

ICE with Box::new_in when taking the Allocator by reference #94008

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

Closed
repnop opened this issue Feb 15, 2022 · 1 comment
Closed

ICE with Box::new_in when taking the Allocator by reference #94008

repnop opened this issue Feb 15, 2022 · 1 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.

Comments

@repnop
Copy link
Contributor

repnop commented Feb 15, 2022

Code

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=852b2d4833c2c88c774a3630f0f6362b

#![feature(allocator_api, nonnull_slice_from_raw_parts, slice_ptr_get)]
#![allow(dead_code, unused_imports, unused_variables)]

use core::{alloc::{AllocError, Layout, Allocator}, cell::Cell, ptr::NonNull};
use std::alloc::Global;

struct ArenaAlloc {}

impl ArenaAlloc {
    pub fn new(size: usize) -> Result<Self, AllocError> {
        todo!()
    }
}

unsafe impl Allocator for &'_ ArenaAlloc {
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        todo!()
    }

    unsafe fn deallocate(&self, _: NonNull<u8>, _: Layout) {}
}

fn main() {
    let allocator = ArenaAlloc::new(16 * 4096).unwrap();
    let my_box = Box::new_in(0u8, &allocator);
}

Error output

thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/compiler/rustc_middle/src/ty/layout.rs:2311:21
stack backtrace:
   0:     0x7fb3399aeb5c - std::backtrace_rs::backtrace::libunwind::trace::h38d656af46687c91
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb3399aeb5c - std::backtrace_rs::backtrace::trace_unsynchronized::h6463e81b43d545da
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb3399aeb5c - std::sys_common::backtrace::_print_fmt::h7d0aeff1635ad318
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fb3399aeb5c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he9ed9f7bc97615c6
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fb339a1067c - core::fmt::write::h26fb070fd492e04f
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/core/src/fmt/mod.rs:1190:17
   5:     0x7fb33999eed8 - std::io::Write::write_fmt::ha7a1cfea3d855428
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/io/mod.rs:1657:15
   6:     0x7fb3399b2ad7 - std::sys_common::backtrace::_print::h6a43ee74b02286e0
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fb3399b2ad7 - std::sys_common::backtrace::print::hfe9d3eef26a9b46f
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fb3399b2ad7 - std::panicking::default_hook::{{closure}}::he3bbb991ed25ca71
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/panicking.rs:295:22
   9:     0x7fb3399b279f - std::panicking::default_hook::h4e425f0c50c308bd
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/panicking.rs:314:9
  10:     0x7fb33a13ecb1 - rustc_driver[a91e56fa9d42f309]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fb3399b33b5 - std::panicking::rust_panic_with_hook::h22c18dec3fc9e708
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/panicking.rs:702:17
  12:     0x7fb3399b3029 - std::panicking::begin_panic_handler::{{closure}}::hd86c4a70dd9a9d4a
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/panicking.rs:586:13
  13:     0x7fb3399af004 - std::sys_common::backtrace::__rust_end_short_backtrace::ha98c5d7cc0ee2da0
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fb3399b2d69 - rust_begin_unwind
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/panicking.rs:584:5
  15:     0x7fb33997ad43 - core::panicking::panic_fmt::h53f61fbdec3080b3
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/core/src/panicking.rs:143:14
  16:     0x7fb33997ac0d - core::panicking::panic::h950eea06a1dc9ad4
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/core/src/panicking.rs:48:5
  17:     0x7fb33b38a7a1 - <&rustc_middle[cc566e06f15dafa0]::ty::TyS as rustc_target[bd8a2977f342684d]::abi::TyAbiInterface<_>>::ty_and_layout_field::field_ty_or_layout::<rustc_codegen_llvm[ce7fced1d54ea27c]::context::CodegenCx>
  18:     0x7fb33b3b4c5a - <rustc_target[bd8a2977f342684d]::abi::TyAndLayout<&rustc_middle[cc566e06f15dafa0]::ty::TyS> as rustc_codegen_llvm[ce7fced1d54ea27c]::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
  19:     0x7fb33b3b5171 - <rustc_target[bd8a2977f342684d]::abi::TyAndLayout<&rustc_middle[cc566e06f15dafa0]::ty::TyS> as rustc_codegen_llvm[ce7fced1d54ea27c]::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
  20:     0x7fb33b3b33ac - <rustc_target[bd8a2977f342684d]::abi::TyAndLayout<&rustc_middle[cc566e06f15dafa0]::ty::TyS> as rustc_codegen_llvm[ce7fced1d54ea27c]::type_of::LayoutLlvmExt>::llvm_type
  21:     0x7fb33b3b2bfb - <rustc_target[bd8a2977f342684d]::abi::TyAndLayout<&rustc_middle[cc566e06f15dafa0]::ty::TyS> as rustc_codegen_llvm[ce7fced1d54ea27c]::type_of::LayoutLlvmExt>::llvm_type
  22:     0x7fb33b3ac7df - <rustc_target[bd8a2977f342684d]::abi::call::FnAbi<&rustc_middle[cc566e06f15dafa0]::ty::TyS> as rustc_codegen_llvm[ce7fced1d54ea27c]::abi::FnAbiLlvmExt>::llvm_type
  23:     0x7fb33b39773c - <rustc_codegen_llvm[ce7fced1d54ea27c]::context::CodegenCx as rustc_codegen_ssa[c5eabbff9f30fa84]::traits::declare::PreDefineMethods>::predefine_fn
  24:     0x7fb33b384a70 - rustc_codegen_llvm[ce7fced1d54ea27c]::base::compile_codegen_unit::module_codegen
  25:     0x7fb33c024436 - <rustc_query_system[4f5991938760a368]::dep_graph::graph::DepGraph<rustc_middle[cc566e06f15dafa0]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[cc566e06f15dafa0]::ty::context::TyCtxt, rustc_span[cd0e477a0d9055ec]::symbol::Symbol, rustc_codegen_ssa[c5eabbff9f30fa84]::ModuleCodegen<rustc_codegen_llvm[ce7fced1d54ea27c]::ModuleLlvm>>
  26:     0x7fb33c0205de - rustc_codegen_llvm[ce7fced1d54ea27c]::base::compile_codegen_unit
  27:     0x7fb33c04d05e - <rustc_codegen_llvm[ce7fced1d54ea27c]::LlvmCodegenBackend as rustc_codegen_ssa[c5eabbff9f30fa84]::traits::backend::CodegenBackend>::codegen_crate
  28:     0x7fb33bfdb337 - <rustc_session[5d2f28b07d0c8873]::session::Session>::time::<alloc[5fc1b733952c8f94]::boxed::Box<dyn core[62aaa051b59bb8a7]::any::Any>, rustc_interface[cc122fef18c9905d]::passes::start_codegen::{closure#0}>
  29:     0x7fb33bff94cc - <rustc_interface[cc122fef18c9905d]::passes::QueryContext>::enter::<<rustc_interface[cc122fef18c9905d]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[62aaa051b59bb8a7]::result::Result<alloc[5fc1b733952c8f94]::boxed::Box<dyn core[62aaa051b59bb8a7]::any::Any>, rustc_errors[73a3c157b3209785]::ErrorReported>>
  30:     0x7fb33bfefe7f - <rustc_interface[cc122fef18c9905d]::queries::Queries>::ongoing_codegen
  31:     0x7fb33bfba97b - rustc_interface[cc122fef18c9905d]::interface::create_compiler_and_run::<core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>, rustc_driver[a91e56fa9d42f309]::run_compiler::{closure#1}>
  32:     0x7fb33bfa0052 - std[b153a624bb710ba]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cc122fef18c9905d]::util::run_in_thread_pool_with_globals<rustc_interface[cc122fef18c9905d]::interface::run_compiler<core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>, rustc_driver[a91e56fa9d42f309]::run_compiler::{closure#1}>::{closure#0}, core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>>::{closure#0}, core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>>
  33:     0x7fb33bfd3169 - <<std[b153a624bb710ba]::thread::Builder>::spawn_unchecked_<rustc_interface[cc122fef18c9905d]::util::run_in_thread_pool_with_globals<rustc_interface[cc122fef18c9905d]::interface::run_compiler<core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>, rustc_driver[a91e56fa9d42f309]::run_compiler::{closure#1}>::{closure#0}, core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>>::{closure#0}, core[62aaa051b59bb8a7]::result::Result<(), rustc_errors[73a3c157b3209785]::ErrorReported>>::{closure#1} as core[62aaa051b59bb8a7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7fb3399bf243 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h353fa42c42b20ec5
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/alloc/src/boxed.rs:1854:9
  35:     0x7fb3399bf243 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0930c1c2fa5dac80
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/alloc/src/boxed.rs:1854:9
  36:     0x7fb3399bf243 - std::sys::unix::thread::Thread::new::thread_start::hb3ede8336acd4f71
                               at /rustc/1e12aef3fab243407f9d71ba9956cb2a1bf105d5/library/std/src/sys/unix/thread.rs:108:17
  37:     0x7fb3398f3609 - start_thread
  38:     0x7fb33980d293 - clone
  39:                0x0 - <unknown>

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.60.0-nightly (1e12aef3f 2022-02-13) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
end of query stack
error: could not compile `playground`
@repnop repnop 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 Feb 15, 2022
@repnop
Copy link
Contributor Author

repnop commented Feb 15, 2022

duplicate of #92054

@repnop repnop closed this as completed Feb 15, 2022
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

No branches or pull requests

1 participant