Skip to content

Commit 3c00f7d

Browse files
committed
Auto merge of #150447 - WaffleLapkin:maybe-dangling-semantics, r=RalfJung
Implement `MaybeDangling` compiler support Tracking issue: rust-lang/rust#118166 cc @RalfJung
2 parents 3047cff + 5701d13 commit 3c00f7d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/base.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
1010
use rustc_index::IndexVec;
1111
use rustc_middle::ty::TypeVisitableExt;
1212
use rustc_middle::ty::adjustment::PointerCoercion;
13-
use rustc_middle::ty::layout::FnAbiOf;
13+
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv as _};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
1515
use rustc_session::config::OutputFilenames;
1616
use rustc_span::Symbol;
@@ -924,19 +924,26 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
924924
count,
925925
}) => {
926926
let dst = codegen_operand(fx, dst);
927-
let pointee = dst
928-
.layout()
929-
.pointee_info_at(fx, rustc_abi::Size::ZERO)
930-
.expect("Expected pointer");
927+
928+
let &ty::RawPtr(pointee, _) = dst.layout().ty.kind() else {
929+
bug!("expected pointer")
930+
};
931+
let pointee_layout = fx
932+
.tcx
933+
.layout_of(fx.typing_env().as_query_input(pointee))
934+
.expect("expected pointee to have a layout");
935+
let elem_size: u64 = pointee_layout.layout.size().bytes();
936+
931937
let dst = dst.load_scalar(fx);
932938
let src = codegen_operand(fx, src).load_scalar(fx);
933939
let count = codegen_operand(fx, count).load_scalar(fx);
934-
let elem_size: u64 = pointee.size.bytes();
940+
935941
let bytes = if elem_size != 1 {
936942
fx.bcx.ins().imul_imm(count, elem_size as i64)
937943
} else {
938944
count
939945
};
946+
940947
fx.bcx.call_memcpy(fx.target_config, dst, src, bytes);
941948
}
942949
},

0 commit comments

Comments
 (0)