widen special case on deref to all non-zst allocators

This commit is contained in:
DrMeepster 2022-03-25 23:14:30 -07:00
parent d4acac935b
commit 46dadfc142
2 changed files with 12 additions and 4 deletions

View File

@ -454,10 +454,8 @@ pub fn codegen_place(
for elem in place_ref.projection[base..].iter() { for elem in place_ref.projection[base..].iter() {
cg_base = match elem.clone() { cg_base = match elem.clone() {
mir::ProjectionElem::Deref => { mir::ProjectionElem::Deref => {
// custom allocators can change box's abi, making it unable to be derefed directly // a box with a non-zst allocator should not be directly dereferenced
if cg_base.layout.ty.is_box() if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 0).is_zst() {
&& matches!(cg_base.layout.abi, Abi::Aggregate { .. } | Abi::Uninhabited)
{
let ptr = cg_base.project_field(bx, 0).project_field(bx, 0); let ptr = cg_base.project_field(bx, 0).project_field(bx, 0);
bx.load_operand(ptr).deref(bx.cx()) bx.load_operand(ptr).deref(bx.cx())

View File

@ -0,0 +1,10 @@
// compile-flags: -O
// compile-pass
#![feature(allocator_api, bench_black_box)]
pub fn main() {
let mut node = Box::new_in([5u8], &std::alloc::Global);
node[0] = 7u8;
std::hint::black_box(node);
}