Commit 32a1736d authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

go/types: add a compiler param to SizesFor

The current StdSizes most closely matches
the gc compiler, and the uses I know of that care
which compiler the sizes are for are all for
the gc compiler, so call the existing
implementation "gc".

Updates #17586
Fixes #19351

Change-Id: I2bdd694518fbe233473896321a1f9758b46ed79b
Reviewed-on: https://go-review.googlesource.com/37666
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 542a60fb
...@@ -35,7 +35,7 @@ func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Pa ...@@ -35,7 +35,7 @@ func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Pa
return &Importer{ return &Importer{
ctxt: ctxt, ctxt: ctxt,
fset: fset, fset: fset,
sizes: types.SizesFor(ctxt.GOARCH), // uses go/types default if GOARCH not found sizes: types.SizesFor(ctxt.Compiler, ctxt.GOARCH), // uses go/types default if GOARCH not found
packages: packages, packages: packages,
} }
} }
......
...@@ -121,7 +121,7 @@ type Config struct { ...@@ -121,7 +121,7 @@ type Config struct {
Importer Importer Importer Importer
// If Sizes != nil, it provides the sizing functions for package unsafe. // If Sizes != nil, it provides the sizing functions for package unsafe.
// Otherwise SizesFor("amd64") is used instead. // Otherwise SizesFor("gc", "amd64") is used instead.
Sizes Sizes Sizes Sizes
// If DisableUnusedImportCheck is set, packages are not checked // If DisableUnusedImportCheck is set, packages are not checked
......
...@@ -247,7 +247,7 @@ func checkPkgFiles(files []*ast.File) { ...@@ -247,7 +247,7 @@ func checkPkgFiles(files []*ast.File) {
report(err) report(err)
}, },
Importer: importer.For(*compiler, nil), Importer: importer.For(*compiler, nil),
Sizes: types.SizesFor(build.Default.GOARCH), Sizes: types.SizesFor(build.Default.Compiler, build.Default.GOARCH),
} }
defer func() { defer func() {
......
...@@ -154,7 +154,7 @@ func (s *StdSizes) Sizeof(T Type) int64 { ...@@ -154,7 +154,7 @@ func (s *StdSizes) Sizeof(T Type) int64 {
} }
// common architecture word sizes and alignments // common architecture word sizes and alignments
var archSizes = map[string]*StdSizes{ var gcArchSizes = map[string]*StdSizes{
"386": {4, 4}, "386": {4, 4},
"arm": {4, 4}, "arm": {4, 4},
"arm64": {8, 8}, "arm64": {8, 8},
...@@ -171,16 +171,21 @@ var archSizes = map[string]*StdSizes{ ...@@ -171,16 +171,21 @@ var archSizes = map[string]*StdSizes{
// update the doc string of SizesFor below. // update the doc string of SizesFor below.
} }
// SizesFor returns the Sizes for one of these architectures: // SizesFor returns the Sizes used by a compiler for an architecture.
// The result is nil if a compiler/architecture pair is not known.
//
// Supported architectures for compiler "gc":
// "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle", // "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle",
// "mips64", "mips64le", "ppc64", "ppc64le", "s390x". // "mips64", "mips64le", "ppc64", "ppc64le", "s390x".
// The result is nil if an architecture is not known. func SizesFor(compiler, arch string) Sizes {
func SizesFor(arch string) Sizes { if compiler != "gc" {
return archSizes[arch] return nil
}
return gcArchSizes[arch]
} }
// stdSizes is used if Config.Sizes == nil. // stdSizes is used if Config.Sizes == nil.
var stdSizes = SizesFor("amd64") var stdSizes = SizesFor("gc", "amd64")
func (conf *Config) alignof(T Type) int64 { func (conf *Config) alignof(T Type) int64 {
if s := conf.Sizes; s != nil { if s := conf.Sizes; s != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment