Skip to content

Commit 050c744

Browse files
author
James Miller
committed
Add uninit intrinsic
1 parent fda176b commit 050c744

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

src/libcore/unstable/intrinsics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub extern "rust-intrinsic" {
4444

4545
pub fn init<T>() -> T;
4646

47+
#[cfg(not(stage0))]
48+
pub unsafe fn uninit<T>() -> T;
49+
4750
pub fn forget<T>(_: T) -> ();
4851

4952
pub fn needs_drop<T>() -> bool;

src/librustc/middle/trans/foreign.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ pub fn trans_intrinsic(ccx: @CrateContext,
715715
Store(bcx, C_null(lltp_ty), fcx.llretptr.get());
716716
}
717717
}
718+
~"uninit" => {
719+
// Do nothing, this is effectively a no-op
720+
}
718721
~"forget" => {}
719722
~"transmute" => {
720723
let (in_type, out_type) = (substs.tys[0], substs.tys[1]);

src/librustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
118118
if abi.is_intrinsic() {
119119
let flags = match *cx.ccx.sess.str_of(i.ident) {
120120
~"size_of" | ~"pref_align_of" | ~"min_align_of" |
121-
~"init" | ~"transmute" | ~"move_val" |
121+
~"uninit" | ~"init" | ~"transmute" | ~"move_val" |
122122
~"move_val_init" => use_repr,
123123

124124
~"get_tydesc" | ~"needs_drop" => use_tydesc,

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,6 +3447,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34473447
~"size_of" |
34483448
~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint()),
34493449
~"init" => (1u, ~[], param(ccx, 0u)),
3450+
~"uninit" => (1u, ~[], param(ccx, 0u)),
34503451
~"forget" => (1u, ~[arg(param(ccx, 0u))], ty::mk_nil()),
34513452
~"transmute" => (2, ~[ arg(param(ccx, 0)) ], param(ccx, 1)),
34523453
~"move_val" | ~"move_val_init" => {

src/test/run-pass/intrinsic-uninit.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.
4+
//
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.
10+
11+
mod rusti {
12+
#[abi = "rust-intrinsic"]
13+
pub extern "rust-intrinsic" {
14+
fn uninit<T>() -> T;
15+
}
16+
}
17+
pub fn main() {
18+
let _a : int = unsafe {rusti::uninit()};
19+
}

0 commit comments

Comments
 (0)