From: Josh Bleecher Snyder Date: Wed, 17 May 2017 15:29:18 +0000 (-0700) Subject: cmd/compile: seed rand with time when race enabled X-Git-Tag: go1.9beta1~238 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ff262913fee4d9d8cc5ce86790d80c070a4b5f89;p=gostls13.git cmd/compile: seed rand with time when race enabled When the race detector is enabled, the compiler randomizes the order in which functions are compiled, in an attempt to shake out bugs. But we never re-seed the rand source, so every execution is identical. Fix that to get more coverage. Change-Id: If5cdde03ef4f1bab5f45e07f03fb6614945481d7 Reviewed-on: https://go-review.googlesource.com/43572 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index fdf3bf7847..355df9d326 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -16,6 +16,7 @@ import ( "math/rand" "sort" "sync" + "time" ) // "Portable" code generation. @@ -249,6 +250,12 @@ func compileSSA(fn *Node, worker int) { pp.Free() } +func init() { + if raceEnabled { + rand.Seed(time.Now().UnixNano()) + } +} + // compileFunctions compiles all functions in compilequeue. // It fans out nBackendWorkers to do the work // and waits for them to complete.