]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent modification of ONAME/OLITERAL/OTYPES nodes in walkexpr
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Mar 2017 23:15:10 +0000 (16:15 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 25 Mar 2017 00:35:35 +0000 (00:35 +0000)
ONAME, OLITERAL, and OTYPE nodes can be shared between functions.
In a concurrent backend, such nodes might be walked concurrently
with being read in other functions.
Arrange for them to be unmodified by walk.

This is a follow-up to CL 38609.

Passes toolstash-check.

Updates #15756

Change-Id: I03ff1d2c0ad81dafac3fd55caa218939cf7c0565
Reviewed-on: https://go-review.googlesource.com/38655
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go

index 3885ca32be0124773d0c597781330d95d6e24826..f98076ac05b1df9fcb437796bf8c6acf52cd39d2 100644 (file)
@@ -1181,7 +1181,11 @@ func updateHasCall(n *Node) {
        }
 
        switch n.Op {
-       case OLITERAL, ONAME:
+       case OLITERAL, ONAME, OTYPE:
+               if b || n.HasCall() {
+                       Fatalf("OLITERAL/ONAME/OTYPE should never have calls: %+v", n)
+               }
+               return
        case OAS:
                if needwritebarrier(n.Left) {
                        b = true
index 0528949081f366f6bad7397449ad01c21ebe135a..c7e35097b8f8ab22cdbeb254db5df233836e0975 100644 (file)
@@ -498,7 +498,10 @@ opswitch:
                Dump("walk", n)
                Fatalf("walkexpr: switch 1 unknown op %+S", n)
 
-       case OTYPE, ONONAME, OINDREGSP, OEMPTY, OGETG:
+       case ONONAME, OINDREGSP, OEMPTY, OGETG:
+
+       case OTYPE, ONAME, OLITERAL:
+               // TODO(mdempsky): Just return n; see discussion on CL 38655.
 
        case ONOT, OMINUS, OPLUS, OCOM, OREAL, OIMAG, ODOTMETH, ODOTINTER,
                OIND, OSPTR, OITAB, OIDATA, ODOTTYPE, ODOTTYPE2, OADDR:
@@ -593,7 +596,7 @@ opswitch:
        case ORECOVER:
                n = mkcall("gorecover", n.Type, init, nod(OADDR, nodfp, nil))
 
-       case OLITERAL, OCLOSUREVAR, OCFUNC, ONAME:
+       case OCLOSUREVAR, OCFUNC:
                n.SetAddable(true)
 
        case OCALLINTER: