diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index d760e47296e17..4c39265c2163e 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -984,6 +984,16 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, lv_temporary), arg_vals(~[frameaddress_val]), ignore); } + ~"morestack_addr" => { + // XXX This is a hack to grab the address of this particular + // native function. There should be a general in-language + // way to do this + let llfty = type_of_fn(bcx.ccx(), ~[], ty::mk_nil(bcx.tcx())); + let morestack_addr = decl_cdecl_fn( + bcx.ccx().llmod, ~"__morestack", llfty); + let morestack_addr = PointerCast(bcx, morestack_addr, T_ptr(T_nil())); + Store(bcx, morestack_addr, fcx.llretptr); + } _ => { // Could we make this an enum rather than a string? does it get // checked earlier? diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index bc9762a43e54d..727210406ebcf 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -2562,6 +2562,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { }); (0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx)) } + ~"morestack_addr" => { + (0u, ~[], ty::mk_nil_ptr(tcx)) + } other => { tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" + other + ~"`"); diff --git a/src/test/run-pass/morestack-address.rs b/src/test/run-pass/morestack-address.rs new file mode 100644 index 0000000000000..7f0adcf0920ff --- /dev/null +++ b/src/test/run-pass/morestack-address.rs @@ -0,0 +1,11 @@ +#[nolink] +#[abi = "rust-intrinsic"] +extern mod rusti { + fn morestack_addr() -> *(); +} + +fn main() { + let addr = rusti::morestack_addr(); + assert addr.is_not_null(); + error!("%?", addr); +} \ No newline at end of file