diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2013-06-13 16:03:58 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2013-06-13 16:03:58 +0400 |
| commit | 591d58a3bb9ea3afea0c898564d972b822212674 (patch) | |
| tree | 81cf4407eb8f27c2120779cc6dbca5844cffc1c8 /src/pkg/runtime | |
| parent | 2ffaefd1618efda434e3176f9bff658fbe70b003 (diff) | |
| download | go-591d58a3bb9ea3afea0c898564d972b822212674.tar.xz | |
cmd/gc: properly race-instrument for loops
Instrumentation of ntest expression should go to ntest->init.
Same for nincr.
Fixes #5340.
R=golang-dev, daniel.morsing
CC=golang-dev
https://golang.org/cl/10026046
Diffstat (limited to 'src/pkg/runtime')
| -rw-r--r-- | src/pkg/runtime/race/testdata/mop_test.go | 88 | ||||
| -rw-r--r-- | src/pkg/runtime/race/testdata/regression_test.go | 17 |
2 files changed, 105 insertions, 0 deletions
diff --git a/src/pkg/runtime/race/testdata/mop_test.go b/src/pkg/runtime/race/testdata/mop_test.go index d221f444e3..620b7ab6e4 100644 --- a/src/pkg/runtime/race/testdata/mop_test.go +++ b/src/pkg/runtime/race/testdata/mop_test.go @@ -306,6 +306,94 @@ func TestRaceRange(t *testing.T) { } } +func TestRaceForInit(t *testing.T) { + c := make(chan int) + x := 0 + go func() { + c <- x + }() + for x = 42; false; { + } + <-c +} + +func TestNoRaceForInit(t *testing.T) { + done := make(chan bool) + c := make(chan bool) + x := 0 + go func() { + for { + _, ok := <-c + if !ok { + done <- true + return + } + x++ + } + }() + i := 0 + for x = 42; i < 10; i++ { + c <- true + } + close(c) + <-done +} + +func TestRaceForTest(t *testing.T) { + done := make(chan bool) + c := make(chan bool) + stop := false + go func() { + for { + _, ok := <-c + if !ok { + done <- true + return + } + stop = true + } + }() + for !stop { + c <- true + } + close(c) + <-done +} + +func TestRaceForIncr(t *testing.T) { + done := make(chan bool) + c := make(chan bool) + x := 0 + go func() { + for { + _, ok := <-c + if !ok { + done <- true + return + } + x++ + } + }() + for i := 0; i < 10; x++ { + i++ + c <- true + } + close(c) + <-done +} + +func TestNoRaceForIncr(t *testing.T) { + done := make(chan bool) + x := 0 + go func() { + x++ + done <- true + }() + for i := 0; i < 0; x++ { + } + <-done +} + func TestRacePlus(t *testing.T) { var x, y, z int ch := make(chan int, 2) diff --git a/src/pkg/runtime/race/testdata/regression_test.go b/src/pkg/runtime/race/testdata/regression_test.go index 49e03d9082..d461269d98 100644 --- a/src/pkg/runtime/race/testdata/regression_test.go +++ b/src/pkg/runtime/race/testdata/regression_test.go @@ -175,3 +175,20 @@ type inltype struct { func inlinetest(p **inltype) *inltype { return *p } + +type iface interface { + Foo() *struct{ b bool } +} + +type Int int + +func (i Int) Foo() *struct{ b bool } { + return &struct{ b bool }{false} +} + +func TestNoRaceForInfiniteLoop(t *testing.T) { + var x Int + // interface conversion causes nodes to be put on init list + for iface(x).Foo().b { + } +} |
