diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-11-13 21:08:26 -0500 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-11-16 17:26:46 +0000 |
commit | 0932dc21180642ce1ff095b9b3e68b06c6f440b3 (patch) | |
tree | f4dbde07ad8c27767b61ae96eb6d38acf8c10976 /src/runtime/race | |
parent | d70a33a40bd2bab2f8cd6ab714c4664ce55dc499 (diff) | |
download | go-0932dc21180642ce1ff095b9b3e68b06c6f440b3.tar.gz go-0932dc21180642ce1ff095b9b3e68b06c6f440b3.zip |
runtime: declare arg size/map for race version of sync/atomic functions
The argument size and map are used in stack scanning if those
functions are deferred. Declare the right argument size and map
so they can be scanned correctly.
Fixes #42599.
Change-Id: I74f9409d574cf7c383f4d8f83e38521026b48861
Reviewed-on: https://go-review.googlesource.com/c/go/+/270079
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/race')
-rw-r--r-- | src/runtime/race/testdata/atomic_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/runtime/race/testdata/atomic_test.go b/src/runtime/race/testdata/atomic_test.go index 769c8d7398..4ce72604a4 100644 --- a/src/runtime/race/testdata/atomic_test.go +++ b/src/runtime/race/testdata/atomic_test.go @@ -299,3 +299,27 @@ func TestNoRaceAtomicCrash(t *testing.T) { }() atomic.AddInt32(nilptr, 1) } + +func TestNoRaceDeferAtomicStore(t *testing.T) { + // Test that when an atomic function is deferred directly, the + // GC scans it correctly. See issue 42599. + type foo struct { + bar int64 + } + + var doFork func(f *foo, depth int) + doFork = func(f *foo, depth int) { + atomic.StoreInt64(&f.bar, 1) + defer atomic.StoreInt64(&f.bar, 0) + if depth > 0 { + for i := 0; i < 2; i++ { + f2 := &foo{} + go doFork(f2, depth-1) + } + } + runtime.GC() + } + + f := &foo{} + doFork(f, 11) +} |