From: Rémy Oudompheng Date: Mon, 24 Dec 2012 11:14:41 +0000 (+0100) Subject: cmd/gc: fix race instrumentation of unaddressable arrays. X-Git-Tag: go1.1rc2~1535 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ecbf99ad975970bd3496880ebf6bc8a2d19b31eb;p=gostls13.git cmd/gc: fix race instrumentation of unaddressable arrays. Fixes #4578. R=dvyukov, golang-dev CC=golang-dev https://golang.org/cl/7005050 --- diff --git a/src/cmd/gc/racewalk.c b/src/cmd/gc/racewalk.c index 1840c6529e..d744cea91e 100644 --- a/src/cmd/gc/racewalk.c +++ b/src/cmd/gc/racewalk.c @@ -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) diff --git a/src/pkg/runtime/race/testdata/map_test.go b/src/pkg/runtime/race/testdata/map_test.go index 36aab7aad2..6f86a50b70 100644 --- a/src/pkg/runtime/race/testdata/map_test.go +++ b/src/pkg/runtime/race/testdata/map_test.go @@ -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)