Add uninit intrinsic

This commit is contained in:
James Miller 2013-05-09 22:23:38 +12:00
parent fda176b070
commit 050c744c23
5 changed files with 27 additions and 1 deletions

View File

@ -44,6 +44,9 @@ pub extern "rust-intrinsic" {
pub fn init<T>() -> T;
#[cfg(not(stage0))]
pub unsafe fn uninit<T>() -> T;
pub fn forget<T>(_: T) -> ();
pub fn needs_drop<T>() -> bool;

View File

@ -715,6 +715,9 @@ pub fn trans_intrinsic(ccx: @CrateContext,
Store(bcx, C_null(lltp_ty), fcx.llretptr.get());
}
}
~"uninit" => {
// Do nothing, this is effectively a no-op
}
~"forget" => {}
~"transmute" => {
let (in_type, out_type) = (substs.tys[0], substs.tys[1]);

View File

@ -118,7 +118,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
if abi.is_intrinsic() {
let flags = match *cx.ccx.sess.str_of(i.ident) {
~"size_of" | ~"pref_align_of" | ~"min_align_of" |
~"init" | ~"transmute" | ~"move_val" |
~"uninit" | ~"init" | ~"transmute" | ~"move_val" |
~"move_val_init" => use_repr,
~"get_tydesc" | ~"needs_drop" => use_tydesc,

View File

@ -3447,6 +3447,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"size_of" |
~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint()),
~"init" => (1u, ~[], param(ccx, 0u)),
~"uninit" => (1u, ~[], param(ccx, 0u)),
~"forget" => (1u, ~[arg(param(ccx, 0u))], ty::mk_nil()),
~"transmute" => (2, ~[ arg(param(ccx, 0)) ], param(ccx, 1)),
~"move_val" | ~"move_val_init" => {

View File

@ -0,0 +1,19 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
mod rusti {
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
fn uninit<T>() -> T;
}
}
pub fn main() {
let _a : int = unsafe {rusti::uninit()};
}