]> Cypherpunks.ru repositories - gostls13.git/blob - test/fixedbugs/issue20780b.go
c8bf1f83499f4d149c4a9396aaf2ba71b252ffcb
[gostls13.git] / test / fixedbugs / issue20780b.go
1 // +build cgo,linux,amd64
2 // run -race
3
4 // Copyright 2021 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 // Test that CL 281293 doesn't interfere with race detector
9 // instrumentation.
10
11 package main
12
13 import "fmt"
14
15 const N = 2e6
16
17 type Big = [N]int
18
19 var sink interface{}
20
21 func main() {
22         g(0, f(0))
23
24         x1 := f(1)
25         sink = &x1
26         g(1, x1)
27         g(7, f(7))
28         g(1, x1)
29
30         x3 := f(3)
31         sink = &x3
32         g(1, x1)
33         g(3, x3)
34
35         h(f(0), x1, f(2), x3, f(4))
36 }
37
38 //go:noinline
39 func f(k int) (x Big) {
40         for i := range x {
41                 x[i] = k*N + i
42         }
43         return
44 }
45
46 //go:noinline
47 func g(k int, x Big) {
48         for i := range x {
49                 if x[i] != k*N+i {
50                         panic(fmt.Sprintf("x%d[%d] = %d", k, i, x[i]))
51                 }
52         }
53 }
54
55 //go:noinline
56 func h(x0, x1, x2, x3, x4 Big) {
57         g(0, x0)
58         g(1, x1)
59         g(2, x2)
60         g(3, x3)
61         g(4, x4)
62 }