Skip to content

Fix ice in box alloc #137

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

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_sysroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.0.0"

[dependencies]
core = { path = "./sysroot_src/library/core" }
compiler_builtins = "0.1"
compiler_builtins = "=0.1.70" # TODO: update back to "0.1" when updating to latest nightly.
alloc = { path = "./sysroot_src/library/alloc" }
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
test = { path = "./sysroot_src/library/test" }
Expand Down
16 changes: 13 additions & 3 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,22 @@ pub trait Deref {
fn deref(&self) -> &Self::Target;
}

pub trait Allocator {
}

pub struct Global;

impl Allocator for Global {}

#[lang = "owned_box"]
pub struct Box<T: ?Sized>(*mut T);
pub struct Box<
T: ?Sized,
A: Allocator = Global,
>(*mut T, A);

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}

impl<T: ?Sized> Drop for Box<T> {
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
fn drop(&mut self) {
// drop is currently performed by compiler.
}
Expand All @@ -468,7 +478,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
}

#[lang = "box_free"]
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
libc::free(ptr as *mut u8);
}

Expand Down
4 changes: 3 additions & 1 deletion src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
ty::Ref(..) | ty::RawPtr(_) => {
return self.field(cx, index).gcc_type(cx, true);
}
ty::Adt(def, _) if def.is_box() => {
// only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty());
return cx.layout_of(ptr_ty).scalar_pair_element_gcc_type(cx, index, immediate);
}
Expand Down