Skip to content

Commit f4f909b

Browse files
committed
rustc: Add min_align_of, pref_align_of intrinsic, deprecate align_of
1 parent 1c46ee3 commit f4f909b

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/rustc/middle/trans/native.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,19 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
764764
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
765765
fcx.llretptr);
766766
}
767+
// FIXME: Transitional. Please remove me.
767768
"align_of" {
768769
Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)),
769770
fcx.llretptr);
770771
}
772+
"min_align_of" {
773+
Store(bcx, C_uint(ccx, shape::llalign_of_min(ccx, lltp_ty)),
774+
fcx.llretptr);
775+
}
776+
"pref_align_of" {
777+
Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)),
778+
fcx.llretptr);
779+
}
771780
"get_tydesc" {
772781
let td = get_tydesc_simple(ccx, tp_ty);
773782
Store(bcx, PointerCast(bcx, td, T_ptr(T_nil())), fcx.llretptr);

src/rustc/middle/trans/type_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
7676
ast_map::node_native_item(i@@{node: native_item_fn(_, _), _}, abi, _) {
7777
if abi == native_abi_rust_intrinsic {
7878
let flags = alt check i.ident {
79-
"size_of" | "align_of" | "init" |
79+
"size_of" | "align_of" |
80+
"pref_align_of" | "min_align_of" | "init" |
8081
"reinterpret_cast" { use_repr }
8182
"get_tydesc" | "needs_drop" { use_tydesc }
8283
"forget" | "addr_of" { 0u }

src/rustc/middle/typeck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,8 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
20072007
}
20082008
let tcx = ccx.tcx;
20092009
let (n_tps, inputs, output) = alt it.ident {
2010-
"size_of" | "align_of" { (1u, [], ty::mk_uint(ccx.tcx)) }
2010+
"size_of" | "align_of" |
2011+
"pref_align_of" | "min_align_of" { (1u, [], ty::mk_uint(ccx.tcx)) }
20112012
"get_tydesc" { (1u, [], ty::mk_nil_ptr(tcx)) }
20122013
"init" { (1u, [], param(ccx, 0u)) }
20132014
"forget" { (1u, [arg(ast::by_move, param(ccx, 0u))],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// xfail-win32 need to investigate alignment on windows
2+
3+
#[abi = "rust-intrinsic"]
4+
native mod rusti {
5+
fn pref_align_of<T>() -> uint;
6+
fn min_align_of<T>() -> uint;
7+
}
8+
9+
#[cfg(target_arch = "x86")]
10+
fn main() {
11+
assert rusti::pref_align_of::<u64>() == 8u;
12+
assert rusti::min_align_of::<u64>() == 4u;
13+
}
14+
15+
#[cfg(target_arch = "x86_64")]
16+
fn main() {
17+
assert rusti::pref_align_of::<u64>() == 8u;
18+
assert rusti::min_align_of::<u64>() == 8u;
19+
}

0 commit comments

Comments
 (0)