]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix race detector instrumentation of type switches.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 16 Jul 2013 07:04:20 +0000 (09:04 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 16 Jul 2013 07:04:20 +0000 (09:04 +0200)
A type switch on a value with map index expressions,
could get a spurious instrumentation from a OTYPESW node.
These nodes do not need instrumentation because after
walk the type switch has been turned into a sequence
of ifs.

Fixes #5890.

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

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

index dbb11d7b89662df6ed2dbdb23faff42c3f2bc4dc..4a905499097677be6aeda681df8e77da6fbaaecb 100644 (file)
@@ -323,10 +323,6 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
                racewalknode(&n->left, init, 0, 0);
                goto ret;
 
-       case OTYPESW:
-               racewalknode(&n->right, init, 0, 0);
-               goto ret;
-
        // should not appear in AST by now
        case OSEND:
        case ORECV:
@@ -402,6 +398,7 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
        case ONONAME:
        case OLITERAL:
        case OSLICESTR:  // always preceded by bounds checking, avoid double instrumentation.
+       case OTYPESW:    // ignored by code generation, do not instrument.
                goto ret;
        }
 
index b5eecd9fdfef08aef29bb3743be1ee6dcd84ffef..fe62bb07e133654572a6c59d521621278c7ac101 100644 (file)
@@ -262,6 +262,25 @@ func TestRaceCaseTypeBody(t *testing.T) {
        <-c
 }
 
+func TestRaceCaseTypeIssue5890(t *testing.T) {
+       // spurious extra instrumentation of the initial interface
+       // value.
+       var x, y int
+       m := make(map[int]map[int]interface{})
+       m[0] = make(map[int]interface{})
+       c := make(chan int, 1)
+       go func() {
+               switch i := m[0][1].(type) {
+               case nil:
+               case *int:
+                       *i = x
+               }
+               c <- 1
+       }()
+       m[0][1] = y
+       <-c
+}
+
 func TestNoRaceRange(t *testing.T) {
        ch := make(chan int, 3)
        a := [...]int{1, 2, 3}