go/analysis/passes/asmdecl: fix nil deref panic
Due to a bug in go/types, a function f(...T) has no type
recorded for the parameter type expression ...T, and apparently
this has never occcured in a file checked by asmdecl before.
The addParams function should really be simplified to use types.Signature.
Updates golang/go#28277
Change-Id: I5b73535a7739b6771ffef1c0a7568f5161d564d5
Reviewed-on: https://go-review.googlesource.com/c/143298
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/go/analysis/passes/asmdecl/asmdecl.go b/go/analysis/passes/asmdecl/asmdecl.go
index 1e6e32a..11dfbf6 100644
--- a/go/analysis/passes/asmdecl/asmdecl.go
+++ b/go/analysis/passes/asmdecl/asmdecl.go
@@ -506,10 +506,20 @@
// addParams adds asmVars for each of the parameters in list.
// isret indicates whether the list are the arguments or the return values.
+ // TODO(adonovan): simplify by passing (*types.Signature).{Params,Results}
+ // instead of list.
addParams := func(list []*ast.Field, isret bool) {
argnum := 0
for _, fld := range list {
t := pass.TypesInfo.Types[fld.Type].Type
+
+ // Work around github.com/golang/go/issues/28277.
+ if t == nil {
+ if ell, ok := fld.Type.(*ast.Ellipsis); ok {
+ t = types.NewSlice(pass.TypesInfo.Types[ell.Elt].Type)
+ }
+ }
+
align := int(arch.sizes.Alignof(t))
size := int(arch.sizes.Sizeof(t))
offset += -offset & (align - 1)
diff --git a/go/analysis/passes/asmdecl/testdata/src/a/asm.go b/go/analysis/passes/asmdecl/testdata/src/a/asm.go
index 3ac1688..661e1a9 100644
--- a/go/analysis/passes/asmdecl/testdata/src/a/asm.go
+++ b/go/analysis/passes/asmdecl/testdata/src/a/asm.go
@@ -44,3 +44,5 @@
func noframe1(x int32)
func noframe2(x int32)
+
+func fvariadic(int, ...int)