From 677d2ff680c188ddb7dcd2bfa6bc7d3f2f2f75b2 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 10 Sep 2018 21:30:46 -0400 Subject: [PATCH] go/ssa: use correct type for variadic parameter in wrapper methods For some reason, the type of the last Param in a wrapper function for a variadic method (T) f(...U) had type [][]U instead of []U. (Possibly a workaround for a long-since fixed bug in go/types?) Added a sanity check to ensure that the common suffix of fn.Params and fn.Signature.Params match in type. Fixes golang/go#27453 Change-Id: I9506f4f67a7ff3a283e9ec0142f638aad00287a9 Reviewed-on: https://go-review.googlesource.com/134515 Reviewed-by: Robert Griesemer --- go/ssa/sanity.go | 11 +++++++++++ go/ssa/wrappers.go | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go/ssa/sanity.go b/go/ssa/sanity.go index 0d13beb9528..6eb64328499 100644 --- a/go/ssa/sanity.go +++ b/go/ssa/sanity.go @@ -446,6 +446,17 @@ func (s *sanity) checkFunction(fn *Function) bool { if p.Parent() != fn { s.errorf("Param %s at index %d has wrong parent", p.Name(), i) } + // Check common suffix of Signature and Params match type. + if sig := fn.Signature; sig != nil { + j := i - len(fn.Params) + sig.Params().Len() // index within sig.Params + if j < 0 { + continue + } + if !types.Identical(p.Type(), sig.Params().At(j).Type()) { + s.errorf("Param %s at index %d has wrong type (%s, versus %s in Signature)", p.Name(), i, p.Type(), sig.Params().At(j).Type()) + + } + } s.checkReferrerList(p) } for i, fv := range fn.FreeVars { diff --git a/go/ssa/wrappers.go b/go/ssa/wrappers.go index 701dd90d7d9..a4ae71d8cfc 100644 --- a/go/ssa/wrappers.go +++ b/go/ssa/wrappers.go @@ -141,13 +141,9 @@ func makeWrapper(prog *Program, sel *types.Selection) *Function { // start is the index of the first regular parameter to use. // func createParams(fn *Function, start int) { - var last *Parameter tparams := fn.Signature.Params() for i, n := start, tparams.Len(); i < n; i++ { - last = fn.addParamObj(tparams.At(i)) - } - if fn.Signature.Variadic() { - last.typ = types.NewSlice(last.typ) + fn.addParamObj(tparams.At(i)) } }