1// run
2
3// Copyright 2021 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Gccgo did not make a copy of a value receiver when using a
8// goroutine to call a method.
9
10package main
11
12import (
13	"sync"
14	"sync/atomic"
15)
16
17var wg sync.WaitGroup
18
19type S struct {
20	i1, i2 int32
21}
22
23var done int32
24
25func (s S) Check(v1, v2 int32) {
26	for {
27		if g1 := atomic.LoadInt32(&s.i1); v1 != g1 {
28			panic(g1)
29		}
30		if g2 := atomic.LoadInt32(&s.i2); v2 != g2 {
31			panic(g2)
32		}
33		if atomic.LoadInt32(&done) != 0 {
34			break
35		}
36	}
37	wg.Done()
38}
39
40func F() {
41	s := S{1, 2}
42	go s.Check(1, 2)
43	atomic.StoreInt32(&s.i1, 3)
44	atomic.StoreInt32(&s.i2, 4)
45	atomic.StoreInt32(&done, 1)
46}
47
48func main() {
49	wg.Add(1)
50	F()
51	wg.Wait()
52}
53