From 0932dc21180642ce1ff095b9b3e68b06c6f440b3 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 13 Nov 2020 21:08:26 -0500 Subject: 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 Run-TryBot: Cherry Zhang Reviewed-by: Keith Randall --- src/runtime/race/testdata/atomic_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/runtime/race/testdata/atomic_test.go') 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) +} -- cgit v1.3