1
0
mirror of https://github.com/golang/go synced 2024-09-29 19:24:33 -06:00

runtime: reorder race detector calls in slicecopy

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>
This commit is contained in:
Keith Randall 2020-02-15 19:23:07 -08:00
parent 0652c80e2a
commit 089e482b3d
2 changed files with 18 additions and 2 deletions

View 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()
}

View 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