]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/escape: support OITAB and OCHECKNIL
authorMatthew Dempsky <mdempsky@google.com>
Mon, 8 Aug 2022 20:23:04 +0000 (13:23 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 9 Aug 2022 16:41:39 +0000 (16:41 +0000)
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>
src/cmd/compile/internal/escape/expr.go
src/cmd/compile/internal/escape/stmt.go

index 9c3e09d10da676757d489e2d9e43b7eaac168cba..f9d83b3f3591ccfe86e8db58e23f89464f4126db 100644 (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:
index 4e8dd904ffb59bbf5ea7e8f7ff9eec96ee1d9e22..8b361bcbd0dfddf4e642659d4918b46ee26b6230 100644 (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++