1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:54:44 -07:00

go/analysis/passes/asmdecl: fix a panic under go1.10

Now that asmdecl is not in the standard repo, we must not assume
that types.SizesFor knows about all architectures and panic if it
does not. This change makes it print a warning and assume 64-bit
norms.

Change-Id: Idacad350b2fc9343adfb32539fec7003b39380ed
Reviewed-on: https://go-review.googlesource.com/c/141679
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2018-10-12 14:52:13 -04:00
parent d1d6d0cbb6
commit c0eb142035

View File

@ -11,6 +11,7 @@ import (
"go/build"
"go/token"
"go/types"
"log"
"regexp"
"strconv"
"strings"
@ -107,7 +108,13 @@ func init() {
for _, arch := range arches {
arch.sizes = types.SizesFor("gc", arch.name)
if arch.sizes == nil {
panic("missing SizesFor for gc/" + arch.name)
// TODO(adonovan): fix: now that asmdecl is not in the standard
// library we cannot assume types.SizesFor is consistent with arches.
// For now, assume 64-bit norms and print a warning.
// But this warning should really be deferred until we attempt to use
// arch, which is very unlikely.
arch.sizes = types.SizesFor("gc", "amd64")
log.Printf("unknown architecture %s", arch.name)
}
arch.intSize = int(arch.sizes.Sizeof(types.Typ[types.Int]))
arch.ptrSize = int(arch.sizes.Sizeof(types.Typ[types.UnsafePointer]))