Add a needs_drop intrinsic

Closes #2055
This commit is contained in:
Marijn Haverbeke 2012-04-18 13:15:02 +02:00
parent 35b8f87b89
commit a0fa099469
3 changed files with 6 additions and 1 deletions

View File

@ -801,6 +801,10 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
"addr_of" {
Store(bcx, get_param(decl, first_real_arg), fcx.llretptr);
}
"needs_drop" {
Store(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)),
fcx.llretptr);
}
}
build_return(bcx);
finish_fn(fcx, lltop);

View File

@ -78,7 +78,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
let flags = alt check i.ident {
"size_of" | "align_of" | "init" |
"reinterpret_cast" { use_repr }
"get_tydesc" { use_tydesc }
"get_tydesc" | "needs_drop" { use_tydesc }
"forget" | "addr_of" { 0u }
};
uint::range(0u, n_tps) {|n| cx.uses[n] |= flags;}

View File

@ -1899,6 +1899,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
param(ccx, 1u)) }
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
other {
tcx.sess.span_err(it.span, "unrecognized intrinsic function: `" +
other + "`");