Skip to content

Commit 04b89b4

Browse files
committed
cmd/compile/internal/ssa: 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: go-delve/delve#3923 Fixes golang#72053
1 parent 194e87e commit 04b89b4

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/cmd/compile/internal/abi/abiutils.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,11 @@ func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 {
679679
off += int64(ts)
680680
if idx < len(types)-1 {
681681
noff := offsets[idx+1]
682+
p := uint64(noff - off)
682683
if noff != off {
683-
padding[idx] = uint64(noff - off)
684+
padding[idx] = p
684685
}
686+
off += int64(p)
685687
}
686688
}
687689
return padding

src/cmd/compile/internal/ssa/debug.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func PopulateABIInRegArgOps(f *Func) {
557557
f.Entry.Values = append(newValues, f.Entry.Values...)
558558
}
559559

560-
// BuildFuncDebug debug information for f, placing the results
560+
// BuildFuncDebug builds debug information for f, placing the results
561561
// in "rval". f must be fully processed, so that each Value is where it
562562
// will be when machine code is emitted.
563563
func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(LocalSlot) int32, rval *FuncDebug) {

src/cmd/compile/internal/test/abiutils_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ func TestABIUtilsComputePadding(t *testing.T) {
390390
padding := make([]uint64, 32)
391391
parm := regRes.InParams()[1]
392392
padding = parm.ComputePadding(padding)
393-
want := "[1 1 1 0]"
393+
want := "[1 0 0 0]"
394394
got := fmt.Sprintf("%+v", padding)
395395
if got != want {
396-
t.Errorf("padding mismatch: wanted %q got %q\n", got, want)
396+
t.Errorf("padding mismatch: wanted %q got %q\n", want, got)
397397
}
398398
}

0 commit comments

Comments
 (0)