cmd/compile: move Used from gc.Node to gc.Name

Node.Used was written to from the backend
concurrently with reads of Node.Class
for the same ONAME Nodes.
I do not know why it was not failing consistently
under the race detector, but it is a race.

This is likely also a problem with Node.HasVal and Node.HasOpt.
They will be handled in a separate CL.

Fix Used by moving it to gc.Name and making it a separate bool.
There was one non-Name use of Used, marking OLABELs as used.
That is no longer needed, now that goto and label checking
happens early in the front end.

Leave the getters and setters in place,
to ease changing the representation in the future
(or changing to an interface!).

Updates #20144

Change-Id: I9bec7c6d33dcb129a4cfa9d338462ea33087f9f7
Reviewed-on: https://go-review.googlesource.com/42015
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2017-04-27 15:17:57 -07:00
parent 94d540a4b6
commit fc08a19cef
15 changed files with 85 additions and 75 deletions

View file

@ -80,8 +80,8 @@ func cmpstackvarlt(a, b *Node) bool {
return a.Xoffset < b.Xoffset
}
if a.Used() != b.Used() {
return a.Used()
if a.Name.Used() != b.Name.Used() {
return a.Name.Used()
}
ap := types.Haspointers(a.Type)
@ -118,13 +118,13 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
// Mark the PAUTO's unused.
for _, ln := range fn.Dcl {
if ln.Class() == PAUTO {
ln.SetUsed(false)
ln.Name.SetUsed(false)
}
}
for _, l := range f.RegAlloc {
if ls, ok := l.(ssa.LocalSlot); ok {
ls.N.(*Node).SetUsed(true)
ls.N.(*Node).Name.SetUsed(true)
}
}
@ -136,10 +136,10 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
n := a.Node.(*Node)
// Don't modify nodfp; it is a global.
if n != nodfp {
n.SetUsed(true)
n.Name.SetUsed(true)
}
case *ssa.AutoSymbol:
a.Node.(*Node).SetUsed(true)
a.Node.(*Node).Name.SetUsed(true)
}
if !scratchUsed {
@ -159,7 +159,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
if n.Op != ONAME || n.Class() != PAUTO {
continue
}
if !n.Used() {
if !n.Name.Used() {
fn.Dcl = fn.Dcl[:i]
break
}
@ -308,7 +308,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
switch n.Class() {
case PAUTO:
if !n.Used() {
if !n.Name.Used() {
Fatalf("debuginfo unused node (AllocFrame should truncate fn.Func.Dcl)")
}
name = obj.NAME_AUTO