mirror of
https://github.com/golang/go
synced 2024-11-26 02:17:58 -07:00
[dev.regabi] cmd/compile: stop analyze NameOffsetExpr.Name_ in escape analysis
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>
This commit is contained in:
parent
7ce2a8383d
commit
88956fc4b1
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user