From ecc6a81617477ddfa961f44e309707a4f864104a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 24 Mar 2017 16:15:10 -0700 Subject: [PATCH] cmd/compile: prevent modification of ONAME/OLITERAL/OTYPES nodes in walkexpr 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/subr.go | 6 +++++- src/cmd/compile/internal/gc/walk.go | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 3885ca32be..f98076ac05 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -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 diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 0528949081..c7e35097b8 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -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: -- 2.48.1