compiler: count locals for vararg inline functions

This commit is contained in:
Evgeniy Stratonikov 2021-02-18 10:25:45 +03:00
parent abee3b5b05
commit f7b9861c11

View file

@ -131,6 +131,11 @@ func (c *codegen) countLocalsInline(decl *ast.FuncDecl, pkg *types.Package, f *f
return false return false
} }
if inner, ok := c.funcs[name]; ok && canInline(name) { if inner, ok := c.funcs[name]; ok && canInline(name) {
sig, ok := c.typeOf(n.Fun).(*types.Signature)
if !ok {
info := c.buildInfo.program.Package(pkg.Path())
sig = info.Types[n.Fun].Type.(*types.Signature)
}
for i := range n.Args { for i := range n.Args {
switch n.Args[i].(type) { switch n.Args[i].(type) {
case *ast.Ident: case *ast.Ident:
@ -139,6 +144,10 @@ func (c *codegen) countLocalsInline(decl *ast.FuncDecl, pkg *types.Package, f *f
size++ size++
} }
} }
// Variadic with direct var args.
if sig.Variadic() && !n.Ellipsis.IsValid() {
size++
}
innerSz, _ := c.countLocalsInline(inner.decl, inner.pkg, inner) innerSz, _ := c.countLocalsInline(inner.decl, inner.pkg, inner)
size += innerSz size += innerSz
} }