From: Matthew Dempsky Date: Mon, 8 Aug 2022 20:23:04 +0000 (-0700) Subject: cmd/compile/internal/escape: support OITAB and OCHECKNIL X-Git-Tag: go1.20rc1~1731 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0c2f87f23d72841544e372fac0bcf5168324d8c9;p=gostls13.git 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 TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Reviewed-by: Cuong Manh Le --- diff --git a/src/cmd/compile/internal/escape/expr.go b/src/cmd/compile/internal/escape/expr.go index 9c3e09d10d..f9d83b3f35 100644 --- a/src/cmd/compile/internal/escape/expr.go +++ b/src/cmd/compile/internal/escape/expr.go @@ -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: diff --git a/src/cmd/compile/internal/escape/stmt.go b/src/cmd/compile/internal/escape/stmt.go index 4e8dd904ff..8b361bcbd0 100644 --- a/src/cmd/compile/internal/escape/stmt.go +++ b/src/cmd/compile/internal/escape/stmt.go @@ -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++