]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: reorder race detector calls in slicecopy
authorKeith Randall <khr@golang.org>
Sun, 16 Feb 2020 03:23:07 +0000 (19:23 -0800)
committerKeith Randall <khr@golang.org>
Tue, 25 Feb 2020 23:41:03 +0000 (23:41 +0000)
In rare circumstances, this helps report a race which would
otherwise go undetected.

Fixes #36794

Change-Id: I8a3c9bd6fc34efa51516393f7ee72531c34fb073
Reviewed-on: https://go-review.googlesource.com/c/go/+/220685
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
src/runtime/race/testdata/slice_test.go
src/runtime/slice.go

index 1ec52438ec498f73314d67d74f8e3a4506c6e5e3..9009a9a4eaf8b0c2b00c70a2cdc0611e8379a6a7 100644 (file)
@@ -5,6 +5,7 @@
 package race_test
 
 import (
+       "sync"
        "testing"
 )
 
@@ -590,3 +591,18 @@ func TestRaceSlice3(t *testing.T) {
        _ = x[:1:i]
        <-done
 }
+
+var saved string
+
+func TestRaceSlice4(t *testing.T) {
+       // See issue 36794.
+       data := []byte("hello there")
+       var wg sync.WaitGroup
+       wg.Add(1)
+       go func() {
+               _ = string(data)
+               wg.Done()
+       }()
+       copy(data, data[2:])
+       wg.Wait()
+}
index 16937a2a0108811c2ece2a80d0e7c32095e4408f..9ad814a5557da2e244bdfd334cef4544e19b7bb3 100644 (file)
@@ -211,12 +211,12 @@ func slicecopy(to, fm slice, width uintptr) int {
        if raceenabled {
                callerpc := getcallerpc()
                pc := funcPC(slicecopy)
-               racewriterangepc(to.array, uintptr(n*int(width)), callerpc, pc)
                racereadrangepc(fm.array, uintptr(n*int(width)), callerpc, pc)
+               racewriterangepc(to.array, uintptr(n*int(width)), callerpc, pc)
        }
        if msanenabled {
-               msanwrite(to.array, uintptr(n*int(width)))
                msanread(fm.array, uintptr(n*int(width)))
+               msanwrite(to.array, uintptr(n*int(width)))
        }
 
        size := uintptr(n) * width