Skip to content

Commit

Permalink
Rollup merge of #94728 - compiler-errors:box-allocator-zst-meta, r=mi…
Browse files Browse the repository at this point in the history
…chaelwoerister

Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST

Basically copy the change in #94043, but for debuginfo.

r? ``@michaelwoerister``

Fixes #94725
  • Loading branch information
Dylan-DPC committed Mar 10, 2022
2 parents 1cf8793 + 307ee94 commit b18b2d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
ty::RawPtr(ty::TypeAndMut { ty: pointee_type, .. }) | ty::Ref(_, pointee_type, _) => {
pointer_or_reference_metadata(cx, t, pointee_type, unique_type_id)
}
ty::Adt(def, _) if def.is_box() => {
// Box<T, A> may have a non-ZST allocator A. In that case, we
// cannot treat Box<T, A> as just an owned alias of `*mut T`.
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
pointer_or_reference_metadata(cx, t, t.boxed_ty(), unique_type_id)
}
ty::FnDef(..) | ty::FnPtr(_) => subroutine_type_metadata(cx, unique_type_id),
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/debuginfo/debuginfo-box-with-large-allocator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// build-pass
// compile-flags: -Cdebuginfo=2
// fixes issue #94725

#![feature(allocator_api)]

use std::alloc::{AllocError, Allocator, Layout};
use std::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);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// check-pass
// build-pass
// compile-flags: -Cdebuginfo=2
// fixes issue #94149

Expand Down

0 comments on commit b18b2d1

Please sign in to comment.