diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 827ab6ee70d7..a69d6b944059 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1594,7 +1594,7 @@ pub fn alloca_maybe_zeroed(cx: @Block, ty: Type, name: &str, zero: bool) -> Valu let p = Alloca(cx, ty, name); if zero { let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.unwrap()); + b.position_before(cx.fcx.alloca_insert_pt.get().unwrap()); memzero(&b, p, ty); } p @@ -1687,7 +1687,7 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext, }, llretptr: Cell::new(None), entry_bcx: None, - alloca_insert_pt: None, + alloca_insert_pt: Cell::new(None), llreturn: None, llself: None, personality: None, @@ -1711,7 +1711,8 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext, Load(entry_bcx, C_null(Type::i8p())); fcx.entry_bcx = Some(entry_bcx); - fcx.alloca_insert_pt = Some(llvm::LLVMGetFirstInstruction(entry_bcx.llbb)); + fcx.alloca_insert_pt.set(Some( + llvm::LLVMGetFirstInstruction(entry_bcx.llbb))); } if !ty::type_is_voidish(ccx.tcx, substd_output_type) { diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index ba39c869ab00..faf210c1a9ea 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -314,7 +314,7 @@ pub fn Alloca(cx: &Block, Ty: Type, name: &str) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); } let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.unwrap()); + b.position_before(cx.fcx.alloca_insert_pt.get().unwrap()); b.alloca(Ty, name) } } @@ -323,7 +323,7 @@ pub fn ArrayAlloca(cx: &Block, Ty: Type, Val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); } let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.unwrap()); + b.position_before(cx.fcx.alloca_insert_pt.get().unwrap()); b.array_alloca(Ty, Val) } } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 199a2b18d753..79b7545b9bc4 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -221,7 +221,7 @@ pub struct FunctionContext { // the function, due to LLVM's quirks. // A marker for the place where we want to insert the function's static // allocas, so that LLVM will coalesce them into a single alloca call. - alloca_insert_pt: Option, + alloca_insert_pt: Cell>, llreturn: Option, // The 'self' value currently in use in this function, if there // is one. @@ -291,7 +291,9 @@ impl FunctionContext { pub fn cleanup(&mut self) { unsafe { - llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt.unwrap()); + llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt + .get() + .unwrap()); } // Remove the cycle between fcx and bcx, so memory can be freed self.entry_bcx = None;