]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/abi: fix ComputePadding
authorDerek Parker <parkerderek86@gmail.com>
Fri, 21 Mar 2025 19:43:32 +0000 (19:43 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 21 Mar 2025 22:02:04 +0000 (15:02 -0700)
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 <cherryyz@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/abi/abiutils.go
src/cmd/compile/internal/ssa/debug.go
src/cmd/compile/internal/test/abiutils_test.go

index e88a80d564623d2030af0c812e2dcc3583bbb755..c013aba19c41a61ef9d14432139f50fe91a0b0e0 100644 (file)
@@ -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 {
index 59d029426443d44ee0689ee9a835bb18d1dc609c..6faef7c25592e66582406014a145de50edd3757f 100644 (file)
@@ -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) {
index b500de9f18a872aa0e2535e942ad0333571ffac3..da807f5a0aab4fee51ace7a58055cd905692ecde 100644 (file)
@@ -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)
        }
 }