Commit ecbf99ad authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: fix race instrumentation of unaddressable arrays.

Fixes #4578.

R=dvyukov, golang-dev
CC=golang-dev
https://golang.org/cl/7005050
parent fcc5cf63
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment