diff --git a/main.go b/main.go index cc84aff1..6d1f500a 100644 --- a/main.go +++ b/main.go @@ -1668,7 +1668,10 @@ func typecheck(pkgPath string, files []*ast.File, origImporter importerWithMap) Instances: make(map[*ast.Ident]types.Instance), } // TODO(mvdan): we should probably set types.Config.GoVersion from go.mod - origTypesConfig := types.Config{Importer: origImporter} + origTypesConfig := types.Config{ + Importer: origImporter, + Sizes: types.SizesFor("gc", sharedCache.GoEnv.GOARCH), + } pkg, err := origTypesConfig.Check(pkgPath, fset, files, info) if err != nil { return nil, nil, fmt.Errorf("typecheck error: %v", err) @@ -2367,8 +2370,8 @@ func flagSetValue(flags []string, name, value string) []string { func fetchGoEnv() error { out, err := exec.Command("go", "env", "-json", - // Keep in sync with sharedCache.GoEnv. - "GOOS", "GOMOD", "GOVERSION", "GOROOT", + // Keep in sync with [sharedCacheType.GoEnv]. + "GOOS", "GOARCH", "GOMOD", "GOVERSION", "GOROOT", ).CombinedOutput() if err != nil { // TODO: cover this in the tests. diff --git a/shared.go b/shared.go index d80ce4bd..cad968be 100644 --- a/shared.go +++ b/shared.go @@ -60,7 +60,8 @@ type sharedCacheType struct { // Filled directly from "go env". // Keep in sync with fetchGoEnv. GoEnv struct { - GOOS string // i.e. the GOOS build target + GOOS string // the GOOS build target + GOARCH string // the GOARCH build target GOMOD string GOVERSION string diff --git a/testdata/script/crossbuild.txtar b/testdata/script/crossbuild.txtar index a6c7f0ce..42223a9e 100644 --- a/testdata/script/crossbuild.txtar +++ b/testdata/script/crossbuild.txtar @@ -40,3 +40,13 @@ import "net/http" func main() { http.ListenAndServe("", nil) } + +-- 32bit.go -- +//go:build arm + +package main + +// Will give "out of bounds" if we don't correctly set up types.Config.Sizes. +const is64bit = ^uint(0) >> 63 // 0 for 32-bit hosts, 1 for 64-bit ones. +var x [1]struct{} +var _ = x[is64bit]