]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix race instrumentation of unaddressable arrays.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 24 Dec 2012 11:14:41 +0000 (12:14 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 24 Dec 2012 11:14:41 +0000 (12:14 +0100)
Fixes #4578.

R=dvyukov, golang-dev
CC=golang-dev
https://golang.org/cl/7005050

src/cmd/gc/racewalk.c
src/pkg/runtime/race/testdata/map_test.go

index 1840c6529e831adfd5e699ecdd9b7b1529482bad..d744cea91e4de955c89b39cff92a5685c996df54 100644 (file)
@@ -282,6 +282,12 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
        case OINDEX:
                if(!isfixedarray(n->left->type))
                        racewalknode(&n->left, init, 0, 0);
+               else if(!islvalue(n->left)) {
+                       // index of unaddressable array, like Map[k][i].
+                       racewalknode(&n->left, init, wr, 0);
+                       racewalknode(&n->right, init, 0, 0);
+                       goto ret;
+               }
                racewalknode(&n->right, init, 0, 0);
                if(n->left->type->etype != TSTRING)
                        callinstr(&n, init, wr, skip);
@@ -422,7 +428,7 @@ callinstr(Node **np, NodeList **init, int wr, int skip)
        int class, res, hascalls;
 
        n = *np;
-       //print("callinstr for %+N [ %O ] etype=%d class=%d\n",
+       //print("callinstr for %+N [ %O ] etype=%E class=%d\n",
        //        n, n->op, n->type ? n->type->etype : -1, n->class);
 
        if(skip || n->type == T || n->type->etype >= TIDEAL)
index 36aab7aad2edaf729319a4fd38abe912acb7002e..6f86a50b70c4d0841f9983f5c80a868420437812 100644 (file)
@@ -30,6 +30,18 @@ func TestRaceMapRW2(t *testing.T) {
        <-ch
 }
 
+func TestRaceMapRWArray(t *testing.T) {
+       // Check instrumentation of unaddressable arrays (issue 4578).
+       m := make(map[int][2]int)
+       ch := make(chan bool, 1)
+       go func() {
+               _ = m[1][1]
+               ch <- true
+       }()
+       m[2] = [2]int{1, 2}
+       <-ch
+}
+
 func TestNoRaceMapRR(t *testing.T) {
        m := make(map[int]int)
        ch := make(chan bool, 1)