]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: stop analyze NameOffsetExpr.Name_ in escape analysis
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 16 Jan 2021 17:17:59 +0000 (00:17 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 17 Jan 2021 06:37:18 +0000 (06:37 +0000)
It is always used with global variables, so we can skip analyze it, the
same as what we are doing for ONAME/PEXTERN nodes.

While at it, add a Fatalf check to ensure NewNameOffsetExpr is only
called for global variables.

For #43737

Change-Id: Iac444ed8d583baba5042bea096531301843b1e8f
Reviewed-on: https://go-review.googlesource.com/c/go/+/284118
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/escape/escape.go
src/cmd/compile/internal/ir/expr.go

index 96c2e02146dcb4411227e2d7f2b463427961c43b..356fbc75f8daaff6cffbd9ef77aa7c2f2425883a 100644 (file)
@@ -585,7 +585,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
        default:
                base.Fatalf("unexpected expr: %v", n)
 
-       case ir.OLITERAL, ir.ONIL, ir.OGETG, ir.OTYPE, ir.OMETHEXPR:
+       case ir.OLITERAL, ir.ONIL, ir.OGETG, ir.OTYPE, ir.OMETHEXPR, ir.ONAMEOFFSET:
                // nop
 
        case ir.ONAME:
@@ -598,10 +598,6 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
                }
                e.flow(k, e.oldLoc(n))
 
-       case ir.ONAMEOFFSET:
-               n := n.(*ir.NameOffsetExpr)
-               e.expr(k, n.Name_)
-
        case ir.OPLUS, ir.ONEG, ir.OBITNOT, ir.ONOT:
                n := n.(*ir.UnaryExpr)
                e.discard(n.X)
@@ -876,8 +872,7 @@ func (e *escape) addr(n ir.Node) hole {
                }
                k = e.oldLoc(n).asHole()
        case ir.ONAMEOFFSET:
-               n := n.(*ir.NameOffsetExpr)
-               k = e.addr(n.Name_)
+               break
        case ir.ODOT:
                n := n.(*ir.SelectorExpr)
                k = e.addr(n.X)
index 46314769733e7b7c29b81efe79841b845911f197..e24b2d5b2cb41093dd637124f761e496a35d2243 100644 (file)
@@ -470,8 +470,8 @@ type NameOffsetExpr struct {
 }
 
 func NewNameOffsetExpr(pos src.XPos, name *Name, offset int64, typ *types.Type) *NameOffsetExpr {
-       if name == nil || IsBlank(name) {
-               base.FatalfAt(pos, "cannot take offset of nil or blank name: %v", name)
+       if name == nil || IsBlank(name) || !(name.Op() == ONAME && name.Class == PEXTERN) {
+               base.FatalfAt(pos, "cannot take offset of nil, blank name or non-global variable: %v", name)
        }
        n := &NameOffsetExpr{Name_: name, Offset_: offset}
        n.typ = typ