mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-24 04:46:58 +00:00
Inline base::malloc_raw_dyn.
Move comment about not unwinding into liballoc.
This commit is contained in:
parent
14ae76d96b
commit
dda6c8cf2f
@ -127,6 +127,7 @@ pub fn usable_size(size: usize, align: usize) -> usize {
|
||||
pub const EMPTY: *mut () = 0x1 as *mut ();
|
||||
|
||||
/// The allocator for unique pointers.
|
||||
// This function must not unwind. If it does, MIR trans will fail.
|
||||
#[cfg(not(test))]
|
||||
#[lang = "exchange_malloc"]
|
||||
#[inline]
|
||||
|
@ -327,8 +327,6 @@ language_item_table! {
|
||||
PanicBoundsCheckFnLangItem, "panic_bounds_check", panic_bounds_check_fn;
|
||||
PanicFmtLangItem, "panic_fmt", panic_fmt;
|
||||
|
||||
// ExchangeMallocFnLangItem cannot unwind, or MIR trans will break. See note
|
||||
// on `malloc_raw_dyn` in librustc_trans/base.rs.
|
||||
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
|
||||
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
|
||||
BoxFreeFnLangItem, "box_free", box_free_fn;
|
||||
|
@ -37,7 +37,7 @@ use back::symbol_export::{self, ExportedSymbols};
|
||||
use llvm::{Linkage, ValueRef, Vector, get_param};
|
||||
use llvm;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
|
||||
use middle::lang_items::StartFnLangItem;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::traits;
|
||||
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
@ -168,33 +168,6 @@ pub fn get_dataptr(bcx: &Builder, fat_ptr: ValueRef) -> ValueRef {
|
||||
bcx.struct_gep(fat_ptr, abi::FAT_PTR_ADDR)
|
||||
}
|
||||
|
||||
fn require_alloc_fn<'blk, 'tcx>(
|
||||
bcx: &BlockAndBuilder<'blk, 'tcx>, info_ty: Ty<'tcx>, it: LangItem
|
||||
) -> DefId {
|
||||
match bcx.tcx().lang_items.require(it) {
|
||||
Ok(id) => id,
|
||||
Err(s) => {
|
||||
bcx.sess().fatal(&format!("allocation of `{}` {}", info_ty, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// malloc_raw_dyn allocates a box to contain a given type, but with a potentially dynamic size.
|
||||
//
|
||||
// MIR requires that ExchangeMallocFnLangItem cannot unwind.
|
||||
pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
|
||||
llty_ptr: Type,
|
||||
info_ty: Ty<'tcx>,
|
||||
size: ValueRef,
|
||||
align: ValueRef)
|
||||
-> ValueRef {
|
||||
// Allocate space:
|
||||
let def_id = require_alloc_fn(bcx, info_ty, ExchangeMallocFnLangItem);
|
||||
let r = Callee::def(bcx.ccx(), def_id, bcx.tcx().intern_substs(&[])).reify(bcx.ccx());
|
||||
bcx.pointercast(bcx.call(r, &[size, align], None), llty_ptr)
|
||||
}
|
||||
|
||||
|
||||
pub fn bin_op_to_icmp_predicate(op: hir::BinOp_,
|
||||
signed: bool)
|
||||
-> llvm::IntPredicate {
|
||||
|
@ -13,6 +13,7 @@ use rustc::ty::{self, Ty};
|
||||
use rustc::ty::cast::{CastTy, IntTy};
|
||||
use rustc::ty::layout::Layout;
|
||||
use rustc::mir;
|
||||
use middle::lang_items::ExchangeMallocFnLangItem;
|
||||
|
||||
use asm;
|
||||
use base;
|
||||
@ -449,7 +450,18 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
let llalign = C_uint(bcx.ccx(), align);
|
||||
let llty_ptr = llty.ptr_to();
|
||||
let box_ty = bcx.tcx().mk_box(content_ty);
|
||||
let val = base::malloc_raw_dyn(&bcx, llty_ptr, box_ty, llsize, llalign);
|
||||
|
||||
// Allocate space:
|
||||
let def_id = match bcx.tcx().lang_items.require(ExchangeMallocFnLangItem) {
|
||||
Ok(id) => id,
|
||||
Err(s) => {
|
||||
bcx.sess().fatal(&format!("allocation of `{}` {}", box_ty, s));
|
||||
}
|
||||
};
|
||||
let r = Callee::def(bcx.ccx(), def_id, bcx.tcx().intern_substs(&[]))
|
||||
.reify(bcx.ccx());
|
||||
let val = bcx.pointercast(bcx.call(r, &[llsize, llalign], None), llty_ptr);
|
||||
|
||||
let operand = OperandRef {
|
||||
val: OperandValue::Immediate(val),
|
||||
ty: box_ty,
|
||||
|
Loading…
Reference in New Issue
Block a user