@@ -141,7 +141,7 @@ func (pa *ABIParamAssignment) RegisterTypesAndOffsets() ([]*types.Type, []int64)
141
141
}
142
142
typs := make ([]* types.Type , 0 , l )
143
143
offs := make ([]int64 , 0 , l )
144
- offs , _ = appendParamOffsets (offs , 0 , pa .Type )
144
+ offs , _ = appendParamOffsets (offs , 0 , pa .Type ) // 0 is aligned for everything.
145
145
return appendParamTypes (typs , pa .Type ), offs
146
146
}
147
147
@@ -193,8 +193,8 @@ func appendParamTypes(rts []*types.Type, t *types.Type) []*types.Type {
193
193
194
194
// appendParamOffsets appends the offset(s) of type t, starting from "at",
195
195
// to input offsets, and returns the longer slice and the next unused offset.
196
+ // at should already be aligned for t.
196
197
func appendParamOffsets (offsets []int64 , at int64 , t * types.Type ) ([]int64 , int64 ) {
197
- at = align (at , t )
198
198
w := t .Size ()
199
199
if w == 0 {
200
200
return offsets , at
@@ -210,11 +210,15 @@ func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int6
210
210
typ := t .Kind ()
211
211
switch typ {
212
212
case types .TARRAY :
213
+ te := t .Elem ()
213
214
for i := int64 (0 ); i < t .NumElem (); i ++ {
214
- offsets , at = appendParamOffsets (offsets , at , t .Elem ())
215
+ at = align (at , te )
216
+ offsets , at = appendParamOffsets (offsets , at , te )
215
217
}
216
218
case types .TSTRUCT :
219
+ at0 := at
217
220
for i , f := range t .Fields () {
221
+ at = at0 + f .Offset // Fields may be over-aligned, see wasm32.
218
222
offsets , at = appendParamOffsets (offsets , at , f .Type )
219
223
if f .Type .Size () == 0 && i == t .NumFields ()- 1 {
220
224
at ++ // last field has zero width
@@ -668,12 +672,13 @@ func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 {
668
672
if len (types ) != nr {
669
673
panic ("internal error" )
670
674
}
675
+ offsets , _ := appendParamOffsets ([]int64 {}, 0 , pa .Type )
671
676
off := int64 (0 )
672
677
for idx , t := range types {
673
678
ts := t .Size ()
674
679
off += int64 (ts )
675
680
if idx < len (types )- 1 {
676
- noff := align ( off , types [idx + 1 ])
681
+ noff := offsets [idx + 1 ]
677
682
if noff != off {
678
683
padding [idx ] = uint64 (noff - off )
679
684
}
0 commit comments