]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: cleanup SWITCH nodes after walk.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 19 Sep 2013 07:23:04 +0000 (09:23 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 19 Sep 2013 07:23:04 +0000 (09:23 +0200)
Keeping pointers from the pre-walk phase confuses
the race detection instrumentation.

Fixes #6418.

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

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

index c5cb49170d37e25552b1c617f615fcaabc568d7a..ced07790ac40ed0eed58631ba74569c9dfcb0db0 100644 (file)
@@ -820,6 +820,9 @@ walkswitch(Node *sw)
                return;
        }
        exprswitch(sw);
+       // Discard old AST elements after a walk. They can confuse racewealk.
+       sw->ntest = nil;
+       sw->list = nil;
 }
 
 /*
index fe62bb07e133654572a6c59d521621278c7ac101..b0b66562cccac738b364d4b2824cd0b291174eb3 100644 (file)
@@ -231,6 +231,22 @@ func TestRaceCaseFallthrough(t *testing.T) {
        <-ch
 }
 
+func TestRaceCaseIssue6418(t *testing.T) {
+       m := map[string]map[string]string{
+               "a": map[string]string{
+                       "b": "c",
+               },
+       }
+       ch := make(chan int)
+       go func() {
+               m["a"]["x"] = "y"
+               ch <- 1
+       }()
+       switch m["a"]["b"] {
+       }
+       <-ch
+}
+
 func TestRaceCaseType(t *testing.T) {
        var x, y int
        var i interface{} = x