mirror of
https://github.com/golang/go
synced 2024-11-18 23:05:06 -07:00
cmd/gc: fix race instrumentation of unaddressable arrays.
Fixes #4578. R=dvyukov, golang-dev CC=golang-dev https://golang.org/cl/7005050
This commit is contained in:
parent
fcc5cf639e
commit
ecbf99ad97
@ -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)
|
||||
|
12
src/pkg/runtime/race/testdata/map_test.go
vendored
12
src/pkg/runtime/race/testdata/map_test.go
vendored
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user