@@ -662,6 +662,26 @@ fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
662
662
}
663
663
}
664
664
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
+ }
665
685
666
686
// Replacement for the LLVM 'GEP' instruction when field-indexing into a
667
687
// 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[]) ->
672
692
result {
673
693
assert ( ty:: type_is_tup_like ( bcx_tcx ( cx) , t) ) ;
674
694
// It might be a static-known type. Handle this.
675
-
676
695
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) ) ;
680
697
}
681
698
// It is a dynamic-containing type that, if we convert directly to an LLVM
682
699
// 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[]) ->
745
762
746
763
let bcx = cx;
747
764
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 ) ) ;
756
766
}
757
767
758
768
0 commit comments