Skip to content

Commit a9c6bfb

Browse files
committed
Switch to use exchange_malloc
1 parent bfa210e commit a9c6bfb

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,47 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9191
let value = &this.thir[value];
9292
let tcx = this.tcx;
9393

94-
let u8_ptr = tcx.mk_mut_ptr(tcx.mk_mach_uint(ty::UintTy::U8));
95-
let storage = this.local_decls.push(LocalDecl::new(u8_ptr, expr_span).internal());
96-
this.cfg.push(
94+
let fake_scope = this.new_source_scope(
95+
expr_span,
96+
LintLevel::Inherited,
97+
Some(Safety::BuiltinUnsafe),
98+
);
99+
let fake_info = SourceInfo { span: expr_span, scope: fake_scope };
100+
101+
let size = this.temp(tcx.types.usize, expr_span);
102+
this.cfg.push_assign(
97103
block,
98-
Statement { source_info, kind: StatementKind::StorageLive(storage) },
104+
fake_info,
105+
size,
106+
Rvalue::NullaryOp(NullOp::SizeOf, value.ty),
99107
);
100108

101-
let box_new = tcx.require_lang_item(LangItem::BoxNew, Some(source_info.span));
102-
let box_new = Operand::function_handle(
103-
tcx,
104-
box_new,
105-
tcx.mk_substs([value.ty.into()].iter()),
106-
source_info.span,
109+
let align = this.temp(tcx.types.usize, expr_span);
110+
this.cfg.push_assign(
111+
block,
112+
fake_info,
113+
align,
114+
Rvalue::NullaryOp(NullOp::AlignOf, value.ty),
107115
);
108116

117+
let exchange_malloc = Operand::function_handle(
118+
tcx,
119+
tcx.require_lang_item(LangItem::ExchangeMalloc, Some(expr_span)),
120+
ty::List::empty(),
121+
expr_span,
122+
);
123+
let storage = this.temp(tcx.mk_mut_ptr(tcx.types.u8), expr_span);
109124
let success = this.cfg.start_new_block();
110125
this.cfg.terminate(
111126
block,
112-
source_info,
127+
fake_info,
113128
TerminatorKind::Call {
114-
func: box_new,
115-
args: Vec::new(),
129+
func: exchange_malloc,
130+
args: vec![Operand::Move(size), Operand::Move(align)],
116131
destination: Some((Place::from(storage), success)),
117132
cleanup: None,
118133
from_hir_call: false,
119-
fn_span: source_info.span,
134+
fn_span: expr_span,
120135
},
121136
);
122137
this.diverge_from(block);

0 commit comments

Comments
 (0)