Skip to content

Commit 45ca9ef

Browse files
committed
cmd/compile: fix register/offset calculation for trailing empty field case.
Includes test. Long term, need to make the offending code be more in terms of official types package offsets, instead of duplicating that logic. For golang#40724. Change-Id: Id33a153f10aed3289cc48d1f99a8e0f6ece9474d Reviewed-on: https://go-review.googlesource.com/c/go/+/306469 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
1 parent e6ac2df commit 45ca9ef

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int6
211211
offsets, at = appendParamOffsets(offsets, at, t.Elem())
212212
}
213213
case types.TSTRUCT:
214-
for _, f := range t.FieldSlice() {
214+
for i, f := range t.FieldSlice() {
215215
offsets, at = appendParamOffsets(offsets, at, f.Type)
216+
if f.Type.Width == 0 && i == t.NumFields()-1 {
217+
at++ // last field has zero width
218+
}
216219
}
217220
at = align(at, t) // type size is rounded up to its alignment
218221
case types.TSLICE:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
var p0exp = S1{
10+
F1: complex(float64(2.3640607624715027), float64(-0.2717825524109192)),
11+
F2: S2{F1: 9},
12+
F3: 103050709,
13+
}
14+
15+
type S1 struct {
16+
F1 complex128
17+
F2 S2
18+
F3 uint64
19+
}
20+
21+
type S2 struct {
22+
F1 uint64
23+
F2 empty
24+
}
25+
26+
type empty struct {
27+
}
28+
29+
//go:noinline
30+
//go:registerparams
31+
func callee(p0 S1) {
32+
if p0 != p0exp {
33+
panic("bad p0")
34+
}
35+
}
36+
37+
func main() {
38+
callee(p0exp)
39+
}

0 commit comments

Comments
 (0)