Skip to content

Commit 09246b5

Browse files
committed
---
yaml --- r: 4302 b: refs/heads/master c: a32f287 h: refs/heads/master v: v3
1 parent 42f62c7 commit 09246b5

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
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: 7b87fa368333130830aea07f3d01aff4b009cbaa
2+
refs/heads/master: a32f287c8a528143566972721be88344a35eb81b

trunk/src/comp/middle/trans.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,26 @@ fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
662662
}
663663
}
664664

665+
// Simple wrapper around GEP that takes an array of ints and wraps them
666+
// in C_int()
667+
fn GEPi(cx: &@block_ctxt, base: ValueRef, ixs: &int[]) -> ValueRef {
668+
let v: ValueRef[] = ~[];
669+
for i: int in ixs { v += ~[C_int(i)]; }
670+
ret cx.build.GEP(base, v);
671+
}
672+
673+
// Increment a pointer by a given amount and then cast it to be a pointer
674+
// to a given type.
675+
fn bump_ptr(bcx: &@block_ctxt, t: &ty::t, base: ValueRef, sz: ValueRef)
676+
-> ValueRef {
677+
let raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
678+
let bumped = bcx.build.GEP(raw, ~[sz]);
679+
if ty::type_has_dynamic_size(bcx_tcx(bcx), t) {
680+
ret bumped;
681+
}
682+
let typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, t));
683+
ret bcx.build.PointerCast(bumped, typ);
684+
}
665685

666686
// Replacement for the LLVM 'GEP' instruction when field-indexing into a
667687
// tuple-like structure (tup, rec) with a static index. This one is driven off
@@ -672,11 +692,8 @@ fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &int[]) ->
672692
result {
673693
assert (ty::type_is_tup_like(bcx_tcx(cx), t));
674694
// It might be a static-known type. Handle this.
675-
676695
if !ty::type_has_dynamic_size(bcx_tcx(cx), t) {
677-
let v: ValueRef[] = ~[];
678-
for i: int in ixs { v += ~[C_int(i)]; }
679-
ret rslt(cx, cx.build.GEP(base, v));
696+
ret rslt(cx, GEPi(cx, base, ixs));
680697
}
681698
// It is a dynamic-containing type that, if we convert directly to an LLVM
682699
// TypeRef, will be all wrong; there's no proper LLVM type to represent
@@ -745,14 +762,7 @@ fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &int[]) ->
745762

746763
let bcx = cx;
747764
let sz = size_of(bcx, prefix_ty);
748-
bcx = sz.bcx;
749-
let raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
750-
let bumped = bcx.build.GEP(raw, ~[sz.val]);
751-
if ty::type_has_dynamic_size(bcx_tcx(cx), s.target) {
752-
ret rslt(bcx, bumped);
753-
}
754-
let typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, s.target));
755-
ret rslt(bcx, bcx.build.PointerCast(bumped, typ));
765+
ret rslt(sz.bcx, bump_ptr(sz.bcx, s.target, base, sz.val));
756766
}
757767

758768

0 commit comments

Comments
 (0)