From ff262913fee4d9d8cc5ce86790d80c070a4b5f89 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 17 May 2017 08:29:18 -0700 Subject: [PATCH] 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 --- src/cmd/compile/internal/gc/pgen.go | 7 +++++++ 1 file changed, 7 insertions(+) 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. -- 2.50.0