diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2013-02-13 18:29:59 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2013-02-13 18:29:59 +0400 |
| commit | 4a524311f4d538a2c5a45d56286fdefbd2cf1c7a (patch) | |
| tree | 5da9ea7d8a44ba286e8cfd0114a6a0ba52af38f6 | |
| parent | 96082a6953583b88b73cf45933325648b66c1654 (diff) | |
| download | go-4a524311f4d538a2c5a45d56286fdefbd2cf1c7a.tar.xz | |
runtime: instrument slicebytetostring for race detection
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7322068
| -rw-r--r-- | src/pkg/runtime/race/testdata/slice_test.go | 20 | ||||
| -rw-r--r-- | src/pkg/runtime/string.goc | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/pkg/runtime/race/testdata/slice_test.go b/src/pkg/runtime/race/testdata/slice_test.go index 1440a5f13e..773463662b 100644 --- a/src/pkg/runtime/race/testdata/slice_test.go +++ b/src/pkg/runtime/race/testdata/slice_test.go @@ -443,3 +443,23 @@ func TestRaceSliceIndexAccess2(t *testing.T) { _ = s[v] <-c } + +func TestRaceSliceByteToString(t *testing.T) { + c := make(chan string) + s := make([]byte, 10) + go func() { + c <- string(s) + }() + s[0] = 42 + <-c +} + +func TestRaceSliceRuneToString(t *testing.T) { + c := make(chan string) + s := make([]rune, 10) + go func() { + c <- string(s) + }() + s[9] = 42 + <-c +} diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index cafcdb6ced..c0d3f2bde9 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -6,6 +6,7 @@ package runtime #include "runtime.h" #include "arch_GOARCH.h" #include "malloc.h" +#include "race.h" String runtime·emptystring; @@ -271,6 +272,12 @@ func intstring(v int64) (s String) { } func slicebytetostring(b Slice) (s String) { + void *pc; + + if(raceenabled) { + pc = runtime·getcallerpc(&b); + runtime·racereadrangepc(b.array, b.len, 1, pc, runtime·slicebytetostring); + } s = gostringsize(b.len); runtime·memmove(s.str, b.array, s.len); } @@ -286,7 +293,12 @@ func slicerunetostring(b Slice) (s String) { intgo siz1, siz2, i; int32 *a; byte dum[8]; + void *pc; + if(raceenabled) { + pc = runtime·getcallerpc(&b); + runtime·racereadrangepc(b.array, b.len*sizeof(*a), sizeof(*a), pc, runtime·slicerunetostring); + } a = (int32*)b.array; siz1 = 0; for(i=0; i<b.len; i++) { |
