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>
This commit is contained in:
Alan Donovan 2018-10-18 21:45:41 -04:00
parent 327a9b56d0
commit 19100bfbe9
2 changed files with 12 additions and 0 deletions

View File

@ -506,10 +506,20 @@ func asmParseDecl(pass *analysis.Pass, decl *ast.FuncDecl) map[string]*asmFunc {
// 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)

View File

@ -44,3 +44,5 @@ func f17584(x float32, y complex64)
func noframe1(x int32)
func noframe2(x int32)
func fvariadic(int, ...int)