]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: clear n->list of OFOR range loop after walk.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 20 May 2013 21:45:22 +0000 (23:45 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 20 May 2013 21:45:22 +0000 (23:45 +0200)
It contains the LHS of the range clause and gets
instrumented by racewalk, but it doesn't have any meaning.

Fixes #5446.

R=golang-dev, dvyukov, daniel.morsing, r
CC=golang-dev
https://golang.org/cl/9560044

src/cmd/gc/range.c
src/pkg/runtime/race/testdata/mop_test.go

index 8af45b9d2742a72a9e3338b33cc8edf7293f8eb8..bd271da386b9b25c7292dd43bb9fd9cff112144f 100644 (file)
@@ -129,6 +129,9 @@ walkrange(Node *n)
        v2 = N;
        if(n->list->next)
                v2 = n->list->next->n;
+       // n->list has no meaning anymore, clear it
+       // to avoid erroneous processing by racewalk.
+       n->list = nil;
        hv2 = N;
 
        if(v2 == N && t->etype == TARRAY) {
index fa7abe0ef83d2a6c0239bc4179d7ce2a95de9772..6d30989193e6be2808dcc14557d61fd056e93edb 100644 (file)
@@ -267,6 +267,19 @@ func TestNoRaceRange(t *testing.T) {
        close(ch)
 }
 
+func TestNoRaceRangeIssue5446(t *testing.T) {
+       ch := make(chan int, 3)
+       a := []int{1, 2, 3}
+       b := []int{4}
+       // used to insert a spurious instrumentation of a[i]
+       // and crash.
+       i := 1
+       for i, a[i] = range b {
+               ch <- i
+       }
+       close(ch)
+}
+
 func TestRaceRange(t *testing.T) {
        const N = 2
        var a [N]int