Skip to content

Error when passing reference to Allocator impl to Box::new_in #92054

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
pjht opened this issue Dec 18, 2021 · 3 comments
Closed

Error when passing reference to Allocator impl to Box::new_in #92054

pjht opened this issue Dec 18, 2021 · 3 comments
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

@pjht
Copy link

pjht commented Dec 18, 2021

Code

Could not isolate, but I think it was caused by passing a reference to a custom impl of Allocator to Box::new_zeroed_slice_in.

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (6bda5b331 2021-12-12)
binary: rustc
commit-hash: 6bda5b331cfe7e04e1fe348c58a928fc2b650f4f
commit-date: 2021-12-12
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: /rustc/6bda5b331cfe7e04e1fe348c58a928fc2b650f4f/compiler/rustc_codegen_ssa/src/mir/operand.rs:132:38: Deref of by-Ref operand OperandRef(Ref((%"alloc::boxed::Box<[u64], &virtual_memory::LazyWrp<spin::mutex::Mutex<virtual_m)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (6bda5b331 2021-12-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental -C link-args=-image-base 0xffff800000000000 --crate-type bin

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

query stack during panic:
end of query stack
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_place
   8: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_rvalue_operand
   9: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  10: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  11: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
  12: rustc_codegen_llvm::base::compile_codegen_unit
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  15: <rustc_interface::queries::Queries>::ongoing_codegen
  16: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  17: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  18: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@pjht pjht 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 Dec 18, 2021
@pjht pjht changed the title Error when passing reference to Allocator impl with fields to Box::new_in Error when passing reference to Allocator impl to Box::new_in Dec 18, 2021
@mwerschy
Copy link

Code

I think this is the same bug. Playground repro.

#![feature(allocator_api)]

use std::alloc::{Allocator, Global, Layout};

fn main() {
  let layout: Layout = None.unwrap();
  let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
  // let box_ = unsafe { Box::from_raw_in(ptr, &Global) }; // ICE 1
  let slice: &mut [u8] = unsafe { std::slice::from_raw_parts_mut(ptr, 0) };
  let box_ = unsafe { Box::from_raw_in(slice, &Global) }; // ICE 2
  box_.len();
}

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (e100ec5bc 2021-12-21)
binary: rustc
commit-hash: e100ec5bc7cd768ec17d75448b29c9ab4a39272b
commit-date: 2021-12-21
host: x86_64-pc-windows-msvc
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: /rustc/e100ec5bc7cd768ec17d75448b29c9ab4a39272b\compiler\rustc_codegen_ssa\src\mir\operand.rs:132:38: Deref of by-Ref operand OperandRef(Ref((%"alloc::boxed::Box<[u8], &alloc::alloc::Global>"*:  %4 = alloca %"alloc::boxed::Box<[u8], &alloc::alloc::Global>", align 8), None, Align 
{ pow2: 3 }) @ TyAndLayout { ty: std::boxed::Box<[u8], &std::alloc::Global>, layout: Layout { fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 16 }], 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: 24 } } })

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (e100ec5bc 2021-12-21) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -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
Backtrace

error: internal compiler error: /rustc/e100ec5bc7cd768ec17d75448b29c9ab4a39272b\compiler\rustc_codegen_ssa\src\mir\operand.rs:132:38: Deref of by-Ref operand OperandRef(Ref((%"alloc::boxed::Box<[u8], &alloc::alloc::Global>"*:  %4 = alloca %"alloc::boxed::Box<[u8], &alloc::alloc::Global>", align 8), None, Align 
{ pow2: 3 }) @ TyAndLayout { ty: std::boxed::Box<[u8], &std::alloc::Global>, layout: Layout { fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 16 }], 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: 24 } } })

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1169:9
stack backtrace:
   0:     0x7fff776a9c4f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd920fc7772705f2f
   1:     0x7fff776d47fa - core::fmt::write::h6cae84e4480d77f7
   2:     0x7fff7769b8b8 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h7935709480648778
   3:     0x7fff776ad3a6 - std::panicking::take_hook::h439fe9c3e72ee47e
   4:     0x7fff776ace89 - std::panicking::take_hook::h439fe9c3e72ee47e
   5:     0x7fff332896d6 - <rustc_lint[c17777233df79390]::BuiltinCombinedLateLintPass as rustc_lint[c17777233df79390]::passes::LateLintPass>::check_fn_post                                                                                                                                                            
   6:     0x7fff776adc09 - std::panicking::rust_panic_with_hook::hf0decd59f5351093
   7:     0x7fff37a828a0 - <rustc_errors[e666500dafc617f3]::diagnostic_builder::DiagnosticBuilder>::code
   8:     0x7fff37a82389 - <rustc_errors[e666500dafc617f3]::diagnostic_builder::DiagnosticBuilder>::code
   9:     0x7fff37d6daa1 - rustc_query_system[da29e76f6eb78471]::query::job::report_cycle
  10:     0x7fff37ab8040 - <rustc_errors[e666500dafc617f3]::registry::InvalidErrorCode as core[695968f75b490638]::fmt::Debug>::fmt
  11:     0x7fff37abf837 - <rustc_errors[e666500dafc617f3]::HandlerInner>::emit_diagnostic
  12:     0x7fff37abcf72 - <rustc_errors[e666500dafc617f3]::Handler>::bug
  13:     0x7fff37781421 - <rustc_middle[2b829493013aafeb]::ty::consts::valtree::ValTree>::zst
  14:     0x7fff37782eb9 - <rustc_middle[2b829493013aafeb]::ty::closure::UpvarBorrow as core[695968f75b490638]::fmt::Debug>::fmt
  15:     0x7fff37d63990 - rustc_middle[2b829493013aafeb]::util::bug::bug_fmt
  16:     0x7fff335e718b - <rustc_target[23893fd9125de42]::abi::TyAndLayout<&rustc_middle[2b829493013aafeb]::ty::TyS> as rustc_codegen_llvm[8c2bb20c9847d66e]::type_of::LayoutLlvmExt>::pointee_info_at
  17:     0x7fff3360a974 - <rustc_codegen_llvm[8c2bb20c9847d66e]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[a10dd870132f8d9c]::back::archive::ArchiveBuilder>::inject_dll_import_lib
  18:     0x7fff335fa85d - <rustc_codegen_llvm[8c2bb20c9847d66e]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[a10dd870132f8d9c]::back::archive::ArchiveBuilder>::inject_dll_import_lib
  19:     0x7fff335f4474 - <rustc_codegen_llvm[8c2bb20c9847d66e]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[a10dd870132f8d9c]::back::archive::ArchiveBuilder>::inject_dll_import_lib
  20:     0x7fff33593c82 - <rustc_codegen_llvm[8c2bb20c9847d66e]::context::CodegenCx as rustc_codegen_ssa[a10dd870132f8d9c]::traits::type_::LayoutTypeMethods>::reg_backend_type
  21:     0x7fff335b203c - <rustc_codegen_llvm[8c2bb20c9847d66e]::LlvmCodegenBackend as rustc_codegen_ssa[a10dd870132f8d9c]::traits::backend::CodegenBackend>::link
  22:     0x7fff335445bf - <rustc_codegen_llvm[8c2bb20c9847d66e]::base::ValueIter as core[695968f75b490638]::iter::traits::iterator::Iterator>::next
  23:     0x7fff3350012e - <rustc_codegen_llvm[8c2bb20c9847d66e]::llvm_::archive_ro::Child as core[695968f75b490638]::ops::drop::Drop>::drop
  24:     0x7fff335428c1 - <rustc_codegen_llvm[8c2bb20c9847d66e]::base::ValueIter as core[695968f75b490638]::iter::traits::iterator::Iterator>::next
  25:     0x7fff335ae070 - <rustc_codegen_llvm[8c2bb20c9847d66e]::LlvmCodegenBackend as rustc_codegen_ssa[a10dd870132f8d9c]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7fff3349ba32 - <rustc_interface[539fe7db8d2f0cb0]::passes::boxed_resolver::BoxedResolver>::to_resolver_outputs
  27:     0x7fff333fba7b - <rustc_interface[539fe7db8d2f0cb0]::queries::Queries>::ongoing_codegen
  28:     0x7fff332afe80 - <rustc_middle[2b829493013aafeb]::ty::SymbolName as core[695968f75b490638]::fmt::Debug>::fmt
  29:     0x7fff332a3f85 - rustc_driver[cf92f2c00c4e0f9e]::pretty::print_after_hir_lowering
  30:     0x7fff332b2ab1 - <rustc_middle[2b829493013aafeb]::ty::SymbolName as core[695968f75b490638]::fmt::Debug>::fmt
  31:     0x7fff332ace53 - rustc_driver[cf92f2c00c4e0f9e]::pretty::print_after_hir_lowering
  32:     0x7fff33327c78 - <rustc_driver[cf92f2c00c4e0f9e]::args::Error as core[695968f75b490638]::fmt::Debug>::fmt
  33:     0x7fff776bb38c - std::sys::windows::thread::Thread::new::h2b78cd4067459812
  34:     0x7fffa73654e0 - BaseThreadInitThunk
  35:     0x7fffa7e6485b - RtlUserThreadStart

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.59.0-nightly (e100ec5bc 2021-12-21) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -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

BGR360 added a commit to BGR360/glacier that referenced this issue Dec 27, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 27, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 17, 2022
Fix ICE when using Box<T, A> with pointer sized A

Fixes rust-lang#78459

Note that using `Box<T, A>` with a more than pointer sized `A` or using a pointer sized `A` with a Box of a DST will produce a different ICE (rust-lang#92054) which is not fixed by this PR.
@beepster4096
Copy link
Contributor

This is a duplicate of #81270

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 28, 2022
Fix ICE when using Box<T, A> with large A

A sequel to rust-lang#94043 that fixes rust-lang#81270 and rust-lang#92054 (duplicate).
@hellow554
Copy link
Contributor

This was not closed by #94414

@jonas-schievink can you please close this? :)

# 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

6 participants