From c0eb142035b5aa4db001a5cc0703b55a8fbf9540 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 12 Oct 2018 14:52:13 -0400 Subject: [PATCH] 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 Run-TryBot: Michael Matloob TryBot-Result: Gobot Gobot --- go/analysis/passes/asmdecl/asmdecl.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/go/analysis/passes/asmdecl/asmdecl.go b/go/analysis/passes/asmdecl/asmdecl.go index bafb39e4..5a076ee2 100644 --- a/go/analysis/passes/asmdecl/asmdecl.go +++ b/go/analysis/passes/asmdecl/asmdecl.go @@ -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]))