1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use lib::llvm::ValueRef;
13 use middle::trans::base::*;
14 use middle::trans::build::*;
15 use middle::trans::common::*;
16 use middle::trans::datum::immediate_rvalue;
17 use middle::trans::glue;
20 pub fn make_free_glue(bcx: @mut Block, vptrptr: ValueRef, box_ty: ty::t)
22 let _icx = push_ctxt("uniq::make_free_glue");
23 let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty);
25 let not_null = IsNotNull(bcx, box_datum.val);
26 do with_cond(bcx, not_null) |bcx| {
27 let body_datum = box_datum.box_body(bcx);
28 let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
30 if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
31 glue::trans_free(bcx, box_datum.val)
33 glue::trans_exchange_free(bcx, box_datum.val)