From 5f646f0a984d43a2e9e99a1338145a862fef425e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 31 Mar 2021 20:02:26 -0400 Subject: [PATCH] cmd/compile: fix parameter offset calculation For struct like { { a int64; b int16 }; c int32 }, on 64-bit machines the offset of c is 16, as the inner struct takes 16 bytes because we round up type size to its alignment. Update the abi package's offset calculation to include this. We only need to do this for struct type, because for all other types its size is naturally aligned. TODO: add a test. Change-Id: I0c661768cb1ed3cb409b20a88b7e23e059f8e3e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/306449 Trust: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Than McIntosh Reviewed-by: David Chase --- src/cmd/compile/internal/abi/abiutils.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index feda2153f7f..56e008830fe 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -214,6 +214,7 @@ func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int6 for _, f := range t.FieldSlice() { offsets, at = appendParamOffsets(offsets, at, f.Type) } + at = align(at, t) // type size is rounded up to its alignment case types.TSLICE: return appendParamOffsets(offsets, at, synthSlice) case types.TSTRING: