From f4f909b8b5d9cb24d3d6e2c10231da28aa627e54 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 26 Apr 2012 22:21:28 -0700 Subject: [PATCH] rustc: Add min_align_of, pref_align_of intrinsic, deprecate align_of --- src/rustc/middle/trans/native.rs | 9 +++++++++ src/rustc/middle/trans/type_use.rs | 3 ++- src/rustc/middle/typeck.rs | 3 ++- src/test/run-pass/intrinsic-alignment.rs | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/intrinsic-alignment.rs diff --git a/src/rustc/middle/trans/native.rs b/src/rustc/middle/trans/native.rs index 42e5669ee4e..46cef5e2bb6 100644 --- a/src/rustc/middle/trans/native.rs +++ b/src/rustc/middle/trans/native.rs @@ -764,10 +764,19 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item, Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)), fcx.llretptr); } + // FIXME: Transitional. Please remove me. "align_of" { Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)), fcx.llretptr); } + "min_align_of" { + Store(bcx, C_uint(ccx, shape::llalign_of_min(ccx, lltp_ty)), + fcx.llretptr); + } + "pref_align_of" { + Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)), + fcx.llretptr); + } "get_tydesc" { let td = get_tydesc_simple(ccx, tp_ty); Store(bcx, PointerCast(bcx, td, T_ptr(T_nil())), fcx.llretptr); diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index 59ae4ec6d04..1a647aa5bf1 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -76,7 +76,8 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) ast_map::node_native_item(i@@{node: native_item_fn(_, _), _}, abi, _) { if abi == native_abi_rust_intrinsic { let flags = alt check i.ident { - "size_of" | "align_of" | "init" | + "size_of" | "align_of" | + "pref_align_of" | "min_align_of" | "init" | "reinterpret_cast" { use_repr } "get_tydesc" | "needs_drop" { use_tydesc } "forget" | "addr_of" { 0u } diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 69936c35b60..e6f112f835d 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -2007,7 +2007,8 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) { } let tcx = ccx.tcx; let (n_tps, inputs, output) = alt it.ident { - "size_of" | "align_of" { (1u, [], ty::mk_uint(ccx.tcx)) } + "size_of" | "align_of" | + "pref_align_of" | "min_align_of" { (1u, [], ty::mk_uint(ccx.tcx)) } "get_tydesc" { (1u, [], ty::mk_nil_ptr(tcx)) } "init" { (1u, [], param(ccx, 0u)) } "forget" { (1u, [arg(ast::by_move, param(ccx, 0u))], diff --git a/src/test/run-pass/intrinsic-alignment.rs b/src/test/run-pass/intrinsic-alignment.rs new file mode 100644 index 00000000000..7841cda4522 --- /dev/null +++ b/src/test/run-pass/intrinsic-alignment.rs @@ -0,0 +1,19 @@ +// xfail-win32 need to investigate alignment on windows + +#[abi = "rust-intrinsic"] +native mod rusti { + fn pref_align_of() -> uint; + fn min_align_of() -> uint; +} + +#[cfg(target_arch = "x86")] +fn main() { + assert rusti::pref_align_of::() == 8u; + assert rusti::min_align_of::() == 4u; +} + +#[cfg(target_arch = "x86_64")] +fn main() { + assert rusti::pref_align_of::() == 8u; + assert rusti::min_align_of::() == 8u; +}