Skip to content

Commit 43751e4

Browse files
committed
rustc: Rename llalign_of_real to llalign_of_pref
This alignment is the "preferred" alignment of a type, which is not necessarily the alignment the compiler will use when packing the type into structures - that is the "ABI" alignment (in LLVM terms). On x86, 64-bit ints have 8-byte preferred alignment, but 4-byte ABI alignment.
1 parent 3c16693 commit 43751e4

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/rustc/middle/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: [ty::t],
18961896
!ty::type_needs_drop(ccx.tcx, subst) {
18971897
let llty = type_of(ccx, subst);
18981898
let size = shape::llsize_of_real(ccx, llty);
1899-
let align = shape::llalign_of_real(ccx, llty);
1899+
let align = shape::llalign_of_pref(ccx, llty);
19001900
// Special value for nil to prevent problems with undef
19011901
// return pointers.
19021902
if size == 1u && ty::type_is_nil(subst) {

src/rustc/middle/trans/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn create_block(cx: block) -> @metadata<block_md> {
282282
fn size_and_align_of(cx: @crate_ctxt, t: ty::t) -> (int, int) {
283283
let llty = type_of::type_of(cx, t);
284284
(shape::llsize_of_real(cx, llty) as int,
285-
shape::llalign_of_real(cx, llty) as int)
285+
shape::llalign_of_pref(cx, llty) as int)
286286
}
287287

288288
fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)

src/rustc/middle/trans/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
765765
fcx.llretptr);
766766
}
767767
"align_of" {
768-
Store(bcx, C_uint(ccx, shape::llalign_of_real(ccx, lltp_ty)),
768+
Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)),
769769
fcx.llretptr);
770770
}
771771
"get_tydesc" {

src/rustc/middle/trans/shape.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
117117
} else {
118118
let llty = type_of::type_of(ccx, elem_t);
119119
min_size += llsize_of_real(ccx, llty);
120-
min_align += llalign_of_real(ccx, llty);
120+
min_align += llalign_of_pref(ccx, llty);
121121
}
122122
}
123123

@@ -190,7 +190,7 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
190190

191191
let llty = trans::common::T_struct(lltys);
192192
let dp = llsize_of_real(ccx, llty) as u16;
193-
let variant_align = llalign_of_real(ccx, llty) as u8;
193+
let variant_align = llalign_of_pref(ccx, llty) as u8;
194194

195195
if max_size < dp { max_size = dp; }
196196
if max_align < variant_align { max_align = variant_align; }
@@ -202,7 +202,7 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
202202
if vec::len(*variants) > 1u {
203203
let variant_t = T_enum_variant(ccx);
204204
max_size += llsize_of_real(ccx, variant_t) as u16;
205-
let align = llalign_of_real(ccx, variant_t) as u8;
205+
let align = llalign_of_pref(ccx, variant_t) as u8;
206206
if max_align < align { max_align = align; }
207207
}
208208

@@ -630,8 +630,10 @@ fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
630630
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t) as uint;
631631
}
632632

633-
// Returns the real alignment of the given type for the current target.
634-
fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
633+
// Returns the preferred alignment of the given type for the current target.
634+
// The preffered alignment may be larger than the alignment used when
635+
// packing the type into structs
636+
fn llalign_of_pref(cx: @crate_ctxt, t: TypeRef) -> uint {
635637
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t) as uint;
636638
}
637639

0 commit comments

Comments
 (0)