1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:20:05 -07:00

cmd/compile/internal/escape: support OITAB and OCHECKNIL

For interface method values, we nil check the receiver value at the
point of evaluating the method value. Currently this is inserted by
the backend during walk, but in some cases it's useful to emit them
upfront instead.

OITAB is essentially a field selection operation, like ODOT, OIDATA,
and OSPTR.

OCHECKNIL is a statement that simply evaluates its unary operand, and
discards the result (after testing for nil).

Change-Id: I583b5170539caa9a87aec661d5c293080fd87fbb
Reviewed-on: https://go-review.googlesource.com/c/go/+/422197
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2022-08-08 13:23:04 -07:00
parent 25d74f324d
commit 0c2f87f23d
2 changed files with 5 additions and 1 deletions

View File

@ -123,7 +123,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
n := n.(*ir.BinaryExpr)
// Note: n.X is not needed because it can never point to memory that might escape.
e.expr(k, n.Y)
case ir.OIDATA, ir.OSPTR:
case ir.OITAB, ir.OIDATA, ir.OSPTR:
n := n.(*ir.UnaryExpr)
e.expr(k, n.X)
case ir.OSLICE2ARRPTR:

View File

@ -74,6 +74,10 @@ func (e *escape) stmt(n ir.Node) {
e.block(n.Body)
e.block(n.Else)
case ir.OCHECKNIL:
n := n.(*ir.UnaryExpr)
e.discard(n.X)
case ir.OFOR, ir.OFORUNTIL:
n := n.(*ir.ForStmt)
e.loopDepth++