cmd/compile: add clear(x) builtin

To clear map, and zero content of slice.

Updates #56351

Change-Id: I5f81dfbc465500f5acadaf2c6beb9b5f0d2c4045
Reviewed-on: https://go-review.googlesource.com/c/go/+/453395
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Cuong Manh Le 2022-11-25 16:11:45 +07:00 committed by Gopher Robot
parent bb4ea80bef
commit b89a840d65
17 changed files with 256 additions and 142 deletions

View file

@ -279,6 +279,10 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node {
case ir.OCOPY:
return walkCopy(n.(*ir.BinaryExpr), init, base.Flag.Cfg.Instrumenting && !base.Flag.CompilingRuntime)
case ir.OCLEAR:
n := n.(*ir.UnaryExpr)
return walkClear(n)
case ir.OCLOSE:
n := n.(*ir.UnaryExpr)
return walkClose(n, init)