compiler: keep traversing after c.countLocalsCall()

Some arguments can be inlined functions themselves thus requiring additional
attention. Otherwise we can get less local variables than really used by
STLOCs (and subsequent program crash).
This commit is contained in:
Roman Khimov 2021-04-05 22:56:59 +03:00
parent dbcd628071
commit 21a7f3d760
3 changed files with 13 additions and 1 deletions

View file

@ -162,7 +162,6 @@ func (c *codegen) countLocalsInline(decl *ast.FuncDecl, pkg *types.Package, f *f
switch n := n.(type) {
case *ast.CallExpr:
size += c.countLocalsCall(n, pkg)
return false
case *ast.FuncType:
num := n.Results.NumFields()
if num != 0 && len(n.Results.List[0].Names) != 0 {

View file

@ -209,6 +209,15 @@ func TestInlineGlobalVariable(t *testing.T) {
})
}
func TestInlineVariadicInInlinedCall(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
func Main() int {
return inline.SumSquared(inline.SumVar(3, 4) - 2, 3)
}`
eval(t, src, big.NewInt(64))
}
func TestInlineConversion(t *testing.T) {
src1 := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"

View file

@ -39,6 +39,10 @@ func VarSum(a int, b ...int) int {
return sum
}
func SumVar(a, b int) int {
return VarSum(a, b)
}
func Concat(n int) int {
return n*100 + b.A*10 + A
}