From: Derek Parker Date: Fri, 21 Mar 2025 19:43:32 +0000 (+0000) Subject: cmd/compile/internal/abi: fix ComputePadding X-Git-Tag: go1.25rc1~630 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=afe11db4a7d61d6ec196577f39b45648f987927d;p=gostls13.git cmd/compile/internal/abi: fix ComputePadding Fixes the ComputePadding calculation to take into account the padding added for the current offset. This fixes an issue where padding can be added incorrectly for certain structs. Related: https://github.com/go-delve/delve/issues/3923 Same as https://go-review.googlesource.com/c/go/+/656736 just without the brittle test. Fixes #72053 Change-Id: I67f157a42f5fc5d3a54d0e9be03488aa44752bcb GitHub-Last-Rev: fabed69a31258fa8c1806f88d1cbcc745c881148 GitHub-Pull-Request: golang/go#72997 Reviewed-on: https://go-review.googlesource.com/c/go/+/659698 Reviewed-by: Cherry Mui Auto-Submit: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index e88a80d564..c013aba19c 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -673,10 +673,9 @@ func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 { panic("internal error") } offsets, _ := appendParamOffsets([]int64{}, 0, pa.Type) - off := int64(0) for idx, t := range types { ts := t.Size() - off += int64(ts) + off := offsets[idx] + ts if idx < len(types)-1 { noff := offsets[idx+1] if noff != off { diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index 59d0294264..6faef7c255 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -557,7 +557,7 @@ func PopulateABIInRegArgOps(f *Func) { f.Entry.Values = append(newValues, f.Entry.Values...) } -// BuildFuncDebug debug information for f, placing the results +// BuildFuncDebug builds debug information for f, placing the results // in "rval". f must be fully processed, so that each Value is where it // will be when machine code is emitted. func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(LocalSlot) int32, rval *FuncDebug) { diff --git a/src/cmd/compile/internal/test/abiutils_test.go b/src/cmd/compile/internal/test/abiutils_test.go index b500de9f18..da807f5a0a 100644 --- a/src/cmd/compile/internal/test/abiutils_test.go +++ b/src/cmd/compile/internal/test/abiutils_test.go @@ -390,9 +390,9 @@ func TestABIUtilsComputePadding(t *testing.T) { padding := make([]uint64, 32) parm := regRes.InParams()[1] padding = parm.ComputePadding(padding) - want := "[1 1 1 0]" + want := "[1 0 0 0]" got := fmt.Sprintf("%+v", padding) if got != want { - t.Errorf("padding mismatch: wanted %q got %q\n", got, want) + t.Errorf("padding mismatch: wanted %q got %q\n", want, got) } }