aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk/complit.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2021-04-12 16:12:20 -0400
committerCherry Zhang <cherryyz@google.com>2021-04-13 21:18:03 +0000
commit9913f821e23e9e26b84ce2b96698140116ee342b (patch)
tree2cb875a81df1063e16fe8fb781e68577daacc8a6 /src/cmd/compile/internal/walk/complit.go
parentc19759aa487f7d6f479daa00e7462425f4efc481 (diff)
downloadgo-9913f821e23e9e26b84ce2b96698140116ee342b.tar.gz
go-9913f821e23e9e26b84ce2b96698140116ee342b.zip
cmd/compile: make map functions ABI insensitive
Following CL 309029, this CL does the same thing for map functions (mapaccess, mapassign, mapdelete). For simplicity, always wrap "defer delete(m, k)". With regabidefers enabled, this call is wrapped in a closure and the rewriting happens automatically. Without regabidefers, it may not be wrapped for certain key types, and then we'd need special handling of the delete (because earlier the order pass does not handle it). And we will turn on defer wrapping by default anyway. Change-Id: I30663b1aa8e1d6f98e1fb81bf8c0c0ce607ab80b Reviewed-on: https://go-review.googlesource.com/c/go/+/309510 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/compile/internal/walk/complit.go')
-rw-r--r--src/cmd/compile/internal/walk/complit.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go
index 54f2c5fefe..abd920d646 100644
--- a/src/cmd/compile/internal/walk/complit.go
+++ b/src/cmd/compile/internal/walk/complit.go
@@ -475,7 +475,10 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
zero := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(tk.NumElem()))
incr := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, ir.NewInt(1)))
- body := ir.NewAssignStmt(base.Pos, lhs, rhs)
+
+ var body ir.Node = ir.NewAssignStmt(base.Pos, lhs, rhs)
+ body = typecheck.Stmt(body) // typechecker rewrites OINDEX to OINDEXMAP
+ body = orderStmtInPlace(body, map[string][]*ir.Name{})
loop := ir.NewForStmt(base.Pos, nil, cond, incr, nil)
loop.Body = []ir.Node{body}
@@ -503,7 +506,10 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, tmpelem, elem))
ir.SetPos(tmpelem)
- appendWalkStmt(init, ir.NewAssignStmt(base.Pos, ir.NewIndexExpr(base.Pos, m, tmpkey), tmpelem))
+ var a ir.Node = ir.NewAssignStmt(base.Pos, ir.NewIndexExpr(base.Pos, m, tmpkey), tmpelem)
+ a = typecheck.Stmt(a) // typechecker rewrites OINDEX to OINDEXMAP
+ a = orderStmtInPlace(a, map[string][]*ir.Name{})
+ appendWalkStmt(init, a)
}
appendWalkStmt(init, ir.NewUnaryExpr(base.Pos, ir.OVARKILL, tmpkey))