Skip to content

Commit

Permalink
cmd/compile: generalize racewalk to instrument (naming change)
Browse files Browse the repository at this point in the history
This is mechanical change that is a step toward reusing the racewalk
pass for a more general instrumentation pass.  The first use will be to
add support for the memory sanitizer.

Change-Id: I75b93b814ac60c1db1660e0b9a9a7d7977d86939
Reviewed-on: https://go-review.googlesource.com/16105
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Reviewed-by: David Crawshaw <[email protected]>
  • Loading branch information
ianlancetaylor committed Oct 21, 2015
1 parent 76dcedc commit 9e902f0
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 79 deletions.
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/gc/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ var flag_race int

var flag_largemodel int

// Whether we are adding any sort of code instrumentation, such as
// when the race detector is enabled.
var instrumenting bool

// Pending annotations for next func declaration.
var (
noescape bool
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/gc/inl.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func caninl(fn *Node) {
}
}

// Runtime package must not be race instrumented.
// Racewalk skips runtime package. However, some runtime code can be
// Runtime package must not be instrumented.
// Instrument skips runtime package. However, some runtime code can be
// inlined into other packages and instrumented there. To avoid this,
// we disable inlining of runtime functions in race mode.
// we disable inlining of runtime functions when instrumenting.
// The example that we observed is inlining of LockOSThread,
// which lead to false race reports on m contents.
if flag_race != 0 && myimportpath == "runtime" {
if instrumenting && myimportpath == "runtime" {
return
}

Expand Down
1 change: 1 addition & 0 deletions src/cmd/compile/internal/gc/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func Main() {
if flag_race != 0 {
racepkg = mkpkg("runtime/race")
racepkg.Name = "race"
instrumenting = true
}

// parse -d argument
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/gc/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func ordermapassign(n *Node, order *Order) {
a = Nod(OAS, m, l.N)
typecheck(&a, Etop)
post = list(post, a)
} else if flag_race != 0 && n.Op == OAS2FUNC && !isblank(l.N) {
} else if instrumenting && n.Op == OAS2FUNC && !isblank(l.N) {
m = l.N
l.N = ordertemp(m.Type, order, false)
a = Nod(OAS, m, l.N)
Expand Down Expand Up @@ -1093,7 +1093,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
OREAL,
ORECOVER:
ordercall(n, order)
if lhs == nil || lhs.Op != ONAME || flag_race != 0 {
if lhs == nil || lhs.Op != ONAME || instrumenting {
n = ordercopyexpr(n, n.Type, order, 0)
}

Expand Down Expand Up @@ -1153,7 +1153,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
// TODO(rsc): The Isfat is for consistency with componentgen and walkexpr.
// It needs to be removed in all three places.
// That would allow inlining x.(struct{*int}) the same as x.(*int).
if !isdirectiface(n.Type) || Isfat(n.Type) || flag_race != 0 {
if !isdirectiface(n.Type) || Isfat(n.Type) || instrumenting {
n = ordercopyexpr(n, n.Type, order, 1)
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/pgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ func compile(fn *Node) {
if nerrors != 0 {
goto ret
}
if flag_race != 0 {
racewalk(Curfn)
if instrumenting {
instrument(Curfn)
}
if nerrors != 0 {
goto ret
Expand Down
Loading

0 comments on commit 9e902f0

Please sign in to comment.