diff options
| author | David Chase <drchase@google.com> | 2024-04-11 17:22:53 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-20 21:19:39 +0000 |
| commit | 22344e11f27d9667e7bbb6209df59e9a9e976d91 (patch) | |
| tree | 10aa3e3f408737c9ff97572ef51f6b039ce76fee /src/cmd | |
| parent | ecad164da79f2cea14c07b9a70dbc3df278ae8d7 (diff) | |
| download | go-22344e11f27d9667e7bbb6209df59e9a9e976d91.tar.xz | |
cmd/compile: add structs.HostLayout
This is for the proposal, plus a few bug fixes
that would/will be necessary when this is put into
actual use.
Fixes #66408.
Updates #63131.
Change-Id: I3a66e09d707dd579c59f155e7f53367f41214c30
Reviewed-on: https://go-review.googlesource.com/c/go/+/578355
Reviewed-by: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd')
5 files changed, 20 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index 607d462493..e88a80d564 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -141,7 +141,7 @@ func (pa *ABIParamAssignment) RegisterTypesAndOffsets() ([]*types.Type, []int64) } typs := make([]*types.Type, 0, l) offs := make([]int64, 0, l) - offs, _ = appendParamOffsets(offs, 0, pa.Type) + offs, _ = appendParamOffsets(offs, 0, pa.Type) // 0 is aligned for everything. return appendParamTypes(typs, pa.Type), offs } @@ -193,8 +193,8 @@ func appendParamTypes(rts []*types.Type, t *types.Type) []*types.Type { // appendParamOffsets appends the offset(s) of type t, starting from "at", // to input offsets, and returns the longer slice and the next unused offset. +// at should already be aligned for t. func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int64) { - at = align(at, t) w := t.Size() if w == 0 { return offsets, at @@ -210,11 +210,15 @@ func appendParamOffsets(offsets []int64, at int64, t *types.Type) ([]int64, int6 typ := t.Kind() switch typ { case types.TARRAY: + te := t.Elem() for i := int64(0); i < t.NumElem(); i++ { - offsets, at = appendParamOffsets(offsets, at, t.Elem()) + at = align(at, te) + offsets, at = appendParamOffsets(offsets, at, te) } case types.TSTRUCT: + at0 := at for i, f := range t.Fields() { + at = at0 + f.Offset // Fields may be over-aligned, see wasm32. offsets, at = appendParamOffsets(offsets, at, f.Type) if f.Type.Size() == 0 && i == t.NumFields()-1 { at++ // last field has zero width @@ -668,12 +672,13 @@ func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 { if len(types) != nr { panic("internal error") } + offsets, _ := appendParamOffsets([]int64{}, 0, pa.Type) off := int64(0) for idx, t := range types { ts := t.Size() off += int64(ts) if idx < len(types)-1 { - noff := align(off, types[idx+1]) + noff := offsets[idx+1] if noff != off { padding[idx] = uint64(noff - off) } diff --git a/src/cmd/compile/internal/compare/compare_test.go b/src/cmd/compile/internal/compare/compare_test.go index 2f76165509..4271effbdb 100644 --- a/src/cmd/compile/internal/compare/compare_test.go +++ b/src/cmd/compile/internal/compare/compare_test.go @@ -23,8 +23,8 @@ func init() { types.PtrSize = 8 types.RegSize = 8 types.MaxWidth = 1 << 50 - typecheck.InitUniverse() base.Ctxt = &obj.Link{Arch: &obj.LinkArch{Arch: &sys.Arch{Alignment: 1, CanMergeLoads: true}}} + typecheck.InitUniverse() } func TestEqStructCost(t *testing.T) { diff --git a/src/cmd/compile/internal/devirtualize/pgo_test.go b/src/cmd/compile/internal/devirtualize/pgo_test.go index cff4d63d51..6153b8c5ec 100644 --- a/src/cmd/compile/internal/devirtualize/pgo_test.go +++ b/src/cmd/compile/internal/devirtualize/pgo_test.go @@ -13,6 +13,7 @@ import ( "cmd/internal/obj" "cmd/internal/pgo" "cmd/internal/src" + "cmd/internal/sys" "testing" ) @@ -23,8 +24,8 @@ func init() { types.PtrSize = 8 types.RegSize = 8 types.MaxWidth = 1 << 50 + base.Ctxt = &obj.Link{Arch: &obj.LinkArch{Arch: &sys.Arch{Alignment: 1, CanMergeLoads: true}}} typecheck.InitUniverse() - base.Ctxt = &obj.Link{} base.Debug.PGODebug = 3 } diff --git a/src/cmd/compile/internal/inline/inlheur/texpr_classify_test.go b/src/cmd/compile/internal/inline/inlheur/texpr_classify_test.go index 587eab03fc..b1cbb2bc0e 100644 --- a/src/cmd/compile/internal/inline/inlheur/texpr_classify_test.go +++ b/src/cmd/compile/internal/inline/inlheur/texpr_classify_test.go @@ -5,10 +5,13 @@ package inlheur import ( + "cmd/compile/internal/base" "cmd/compile/internal/ir" "cmd/compile/internal/typecheck" "cmd/compile/internal/types" + "cmd/internal/obj" "cmd/internal/src" + "cmd/internal/sys" "go/constant" "testing" ) @@ -21,6 +24,8 @@ func init() { types.PtrSize = 8 types.RegSize = 8 types.MaxWidth = 1 << 50 + base.Ctxt = &obj.Link{Arch: &obj.LinkArch{Arch: &sys.Arch{Alignment: 1, CanMergeLoads: true}}} + typecheck.InitUniverse() local = types.NewPkg("", "") fsym := &types.Sym{ diff --git a/src/cmd/compile/internal/ssa/export_test.go b/src/cmd/compile/internal/ssa/export_test.go index b2c4b1997f..c33c77f891 100644 --- a/src/cmd/compile/internal/ssa/export_test.go +++ b/src/cmd/compile/internal/ssa/export_test.go @@ -7,6 +7,7 @@ package ssa import ( "testing" + "cmd/compile/internal/base" "cmd/compile/internal/ir" "cmd/compile/internal/typecheck" "cmd/compile/internal/types" @@ -15,6 +16,7 @@ import ( "cmd/internal/obj/s390x" "cmd/internal/obj/x86" "cmd/internal/src" + "cmd/internal/sys" ) var CheckFunc = checkFunc @@ -115,6 +117,7 @@ func init() { types.RegSize = 8 types.MaxWidth = 1 << 50 + base.Ctxt = &obj.Link{Arch: &obj.LinkArch{Arch: &sys.Arch{Alignment: 1, CanMergeLoads: true}}} typecheck.InitUniverse() testTypes.SetTypPtrs() } |
