Skip to content

Commit 46dadfc

Browse files
committed
widen special case on deref to all non-zst allocators
1 parent d4acac9 commit 46dadfc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
454454
for elem in place_ref.projection[base..].iter() {
455455
cg_base = match elem.clone() {
456456
mir::ProjectionElem::Deref => {
457-
// custom allocators can change box's abi, making it unable to be derefed directly
458-
if cg_base.layout.ty.is_box()
459-
&& matches!(cg_base.layout.abi, Abi::Aggregate { .. } | Abi::Uninhabited)
460-
{
457+
// a box with a non-zst allocator should not be directly dereferenced
458+
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 0).is_zst() {
461459
let ptr = cg_base.project_field(bx, 0).project_field(bx, 0);
462460

463461
bx.load_operand(ptr).deref(bx.cx())

src/test/ui/box/issue-95036.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -O
2+
// compile-pass
3+
4+
#![feature(allocator_api, bench_black_box)]
5+
6+
pub fn main() {
7+
let mut node = Box::new_in([5u8], &std::alloc::Global);
8+
node[0] = 7u8;
9+
std::hint::black_box(node);
10+
}

0 commit comments

Comments
 (0)