diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 75271804b791..7d5ae5c7c1bf 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -1113,8 +1113,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
llvm::LLVMGetParam(fcx.llfn, 0)
} else {
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
- let bcx = fcx.entry_bcx.borrow().clone().unwrap();
- Alloca(bcx, lloutputtype, "__make_return_pointer")
+ AllocaFcx(fcx, lloutputtype, "__make_return_pointer")
}
}
}
@@ -1155,7 +1154,6 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
llfn: llfndecl,
llenv: None,
llretptr: Cell::new(None),
- entry_bcx: RefCell::new(None),
alloca_insert_pt: Cell::new(None),
llreturn: Cell::new(None),
personality: Cell::new(None),
@@ -1185,11 +1183,9 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
/// and allocating space for the return pointer.
pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
skip_retptr: bool,
- output_type: ty::t) {
+ output_type: ty::t) -> &'a Block<'a> {
let entry_bcx = fcx.new_temp_block("entry-block");
- *fcx.entry_bcx.borrow_mut() = Some(entry_bcx);
-
// Use a dummy instruction as the insertion point for all allocas.
// This is later removed in FunctionContext::cleanup.
fcx.alloca_insert_pt.set(Some(unsafe {
@@ -1211,6 +1207,8 @@ pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
fcx.llretptr.set(Some(make_return_pointer(fcx, substd_output_type)));
}
}
+
+ entry_bcx
}
// NB: must keep 4 fns in sync:
@@ -1365,15 +1363,11 @@ pub fn trans_closure(ccx: &CrateContext,
param_substs,
Some(body.span),
&arena);
- init_function(&fcx, false, output_type);
+ let mut bcx = init_function(&fcx, false, output_type);
// cleanup scope for the incoming arguments
let arg_scope = fcx.push_custom_cleanup_scope();
- // Create the first basic block in the function and keep a handle on it to
- // pass to finish_fn later.
- let bcx_top = fcx.entry_bcx.borrow().clone().unwrap();
- let mut bcx = bcx_top;
let block_ty = node_id_type(bcx, body.id);
// Set up arguments to the function.
@@ -1500,14 +1494,12 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
let arena = TypedArena::new();
let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
param_substs, None, &arena);
- init_function(&fcx, false, result_ty);
+ let bcx = init_function(&fcx, false, result_ty);
let arg_tys = ty::ty_fn_args(ctor_ty);
let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice());
- let bcx = fcx.entry_bcx.borrow().clone().unwrap();
-
if !type_is_zero_size(fcx.ccx, result_ty) {
let repr = adt::represent_type(ccx, result_ty);
adt::trans_start_init(bcx, &*repr, fcx.llretptr.get().unwrap(), disr);
diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs
index 0cc4a9223d49..c4e5fa3fa687 100644
--- a/src/librustc/middle/trans/callee.rs
+++ b/src/librustc/middle/trans/callee.rs
@@ -279,10 +279,9 @@ pub fn trans_unboxing_shim(bcx: &Block,
&empty_param_substs,
None,
&block_arena);
- init_function(&fcx, false, return_type);
+ let mut bcx = init_function(&fcx, false, return_type);
// Create the substituted versions of the self type.
- let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
let arg_scope = fcx.push_custom_cleanup_scope();
let arg_scope_id = cleanup::CustomScope(arg_scope);
let boxed_arg_types = ty::ty_fn_args(boxed_function_type);
diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs
index f956b58031cd..b2564936fa40 100644
--- a/src/librustc/middle/trans/closure.rs
+++ b/src/librustc/middle/trans/closure.rs
@@ -424,8 +424,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
let empty_param_substs = param_substs::empty();
let fcx = new_fn_ctxt(ccx, llfn, -1, true, f.sig.output,
&empty_param_substs, None, &arena);
- init_function(&fcx, true, f.sig.output);
- let bcx = fcx.entry_bcx.borrow().clone().unwrap();
+ let bcx = init_function(&fcx, true, f.sig.output);
let args = create_datums_for_fn_args(&fcx,
ty::ty_fn_args(closure_ty)
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs
index b1577a6abfe1..33e8d1736fb3 100644
--- a/src/librustc/middle/trans/common.rs
+++ b/src/librustc/middle/trans/common.rs
@@ -239,8 +239,6 @@ pub struct FunctionContext<'a> {
// always be Some.
pub llretptr: Cell