Skip to content

Commit fd1938b

Browse files
committed
---
yaml --- r: 1460 b: refs/heads/master c: bdbaf0c h: refs/heads/master v: v3
1 parent a913290 commit fd1938b

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 348c77c31b7dcd5be85438dfcf4292f7e0951dd6
2+
refs/heads/master: bdbaf0c7897366f17e36797e5c9fc7ef12fa9fce

trunk/src/comp/middle/trans.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -851,50 +851,45 @@ fn align_of(@block_ctxt cx, @ty.t t) -> result {
851851
}
852852

853853
fn dynamic_size_of(@block_ctxt cx, @ty.t t) -> result {
854+
fn align_elements(@block_ctxt cx, vec[@ty.t] elts) -> result {
855+
//
856+
// C padding rules:
857+
//
858+
//
859+
// - Pad after each element so that next element is aligned.
860+
// - Pad after final structure member so that whole structure
861+
// is aligned to max alignment of interior.
862+
//
863+
auto off = C_int(0);
864+
auto max_align = C_int(1);
865+
auto bcx = cx;
866+
for (@ty.t e in elts) {
867+
auto elt_align = align_of(bcx, e);
868+
bcx = elt_align.bcx;
869+
auto elt_size = size_of(bcx, e);
870+
bcx = elt_size.bcx;
871+
auto aligned_off = align_to(bcx, off, elt_align.val);
872+
off = cx.build.Add(aligned_off, elt_size.val);
873+
max_align = umax(bcx, max_align, elt_align.val);
874+
}
875+
off = align_to(bcx, off, max_align);
876+
ret res(bcx, off);
877+
}
878+
854879
alt (t.struct) {
855880
case (ty.ty_param(?p)) {
856881
auto szptr = field_of_tydesc(cx, t, abi.tydesc_field_size);
857882
ret res(szptr.bcx, szptr.bcx.build.Load(szptr.val));
858883
}
859884
case (ty.ty_tup(?elts)) {
860-
//
861-
// C padding rules:
862-
//
863-
//
864-
// - Pad after each element so that next element is aligned.
865-
// - Pad after final structure member so that whole structure
866-
// is aligned to max alignment of interior.
867-
//
868-
auto off = C_int(0);
869-
auto max_align = C_int(1);
870-
auto bcx = cx;
871-
for (@ty.t e in elts) {
872-
auto elt_align = align_of(bcx, e);
873-
bcx = elt_align.bcx;
874-
auto elt_size = size_of(bcx, e);
875-
bcx = elt_size.bcx;
876-
auto aligned_off = align_to(bcx, off, elt_align.val);
877-
off = cx.build.Add(aligned_off, elt_size.val);
878-
max_align = umax(bcx, max_align, elt_align.val);
879-
}
880-
off = align_to(bcx, off, max_align);
881-
ret res(bcx, off);
885+
ret align_elements(cx, elts);
882886
}
883887
case (ty.ty_rec(?flds)) {
884-
auto off = C_int(0);
885-
auto max_align = C_int(1);
886-
auto bcx = cx;
888+
let vec[@ty.t] tys = vec();
887889
for (ty.field f in flds) {
888-
auto elt_align = align_of(bcx, f.ty);
889-
bcx = elt_align.bcx;
890-
auto elt_size = size_of(bcx, f.ty);
891-
bcx = elt_size.bcx;
892-
auto aligned_off = align_to(bcx, off, elt_align.val);
893-
off = cx.build.Add(aligned_off, elt_size.val);
894-
max_align = umax(bcx, max_align, elt_align.val);
890+
tys += vec(f.ty);
895891
}
896-
off = align_to(bcx, off, max_align);
897-
ret res(bcx, off);
892+
ret align_elements(cx, tys);
898893
}
899894
}
900895
}

0 commit comments

Comments
 (0)