diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-01-16 18:25:00 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-01-17 05:08:05 +0000 |
commit | ba0e8a92fa74768feaccb8c3e4e5791b2dbc382f (patch) | |
tree | d57295fba1d673dbd01e24c1e2d6cf7e1efc2745 /src/cmd/compile/internal/walk/complit.go | |
parent | 78e5aabcdb8aeae58a6437a3051fde3555ee0bf2 (diff) | |
download | go-ba0e8a92fa74768feaccb8c3e4e5791b2dbc382f.tar.gz go-ba0e8a92fa74768feaccb8c3e4e5791b2dbc382f.zip |
[dev.regabi] cmd/compile: refactor temp construction in walk
This CL adds a few new helper functions for constructing and
initializing temporary variables during walk.
Passes toolstash -cmp.
Change-Id: I54965d992cd8dfef7cb7dc92a17c88372e52a0d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/284224
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/walk/complit.go')
-rw-r--r-- | src/cmd/compile/internal/walk/complit.go | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go index f82ef69ca99..a7db4535501 100644 --- a/src/cmd/compile/internal/walk/complit.go +++ b/src/cmd/compile/internal/walk/complit.go @@ -344,30 +344,14 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes) if !types.Identical(t, x.Type()) { panic("dotdotdot base type does not match order's assigned type") } - - if vstat == nil { - a = ir.NewAssignStmt(base.Pos, x, nil) - a = typecheck.Stmt(a) - init.Append(a) // zero new temp - } else { - // Declare that we're about to initialize all of x. - // (Which happens at the *vauto = vstat below.) - init.Append(ir.NewUnaryExpr(base.Pos, ir.OVARDEF, x)) - } - - a = typecheck.NodAddr(x) + a = initStackTemp(init, x, vstat != nil) } else if n.Esc() == ir.EscNone { - a = typecheck.Temp(t) if vstat == nil { - a = ir.NewAssignStmt(base.Pos, typecheck.Temp(t), nil) - a = typecheck.Stmt(a) - init.Append(a) // zero new temp - a = a.(*ir.AssignStmt).X - } else { - init.Append(ir.NewUnaryExpr(base.Pos, ir.OVARDEF, a)) + // TODO(mdempsky): Remove this useless temporary. + // It's only needed to keep toolstash happy. + typecheck.Temp(t) } - - a = typecheck.NodAddr(a) + a = initStackTemp(init, typecheck.Temp(t), vstat != nil) } else { a = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(t)) } @@ -550,9 +534,8 @@ func anylit(n ir.Node, var_ ir.Node, init *ir.Nodes) { var r ir.Node if n.Prealloc != nil { - // n.Right is stack temporary used as backing store. - appendWalkStmt(init, ir.NewAssignStmt(base.Pos, n.Prealloc, nil)) // zero backing store, just in case (#18410) - r = typecheck.NodAddr(n.Prealloc) + // n.Prealloc is stack temporary used as backing store. + r = initStackTemp(init, n.Prealloc, false) } else { r = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(n.X.Type())) r.SetEsc(n.Esc()) |