]> Cypherpunks.ru repositories - gostls13.git/blob - test/nowritebarrier.go
cmd/compile: intrinsify Sub64 on mips64
[gostls13.git] / test / nowritebarrier.go
1 // errorcheck -+
2
3 // Copyright 2016 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 // Test go:nowritebarrier and related directives.
8
9 package p
10
11 type t struct {
12         f *t
13 }
14
15 var x t
16 var y *t
17
18 //go:nowritebarrier
19 func a1() {
20         x.f = y // ERROR "write barrier prohibited"
21         a2()    // no error
22 }
23
24 //go:noinline
25 func a2() {
26         x.f = y
27 }
28
29 //go:nowritebarrierrec
30 func b1() {
31         b2()
32 }
33
34 //go:noinline
35 func b2() {
36         x.f = y // ERROR "write barrier prohibited by caller"
37 }
38
39 // Test recursive cycles through nowritebarrierrec and yeswritebarrierrec.
40
41 //go:nowritebarrierrec
42 func c1() {
43         c2()
44 }
45
46 //go:yeswritebarrierrec
47 func c2() {
48         c3()
49 }
50
51 func c3() {
52         x.f = y
53         c4()
54 }
55
56 //go:nowritebarrierrec
57 func c4() {
58         c2()
59 }
60
61 //go:nowritebarrierrec
62 func d1() {
63         d2()
64 }
65
66 func d2() {
67         d3()
68 }
69
70 //go:noinline
71 func d3() {
72         x.f = y // ERROR "write barrier prohibited by caller"
73         d4()
74 }
75
76 //go:yeswritebarrierrec
77 func d4() {
78         d2()
79 }
80
81 //go:noinline
82 func systemstack(func()) {}
83
84 //go:nowritebarrierrec
85 func e1() {
86         systemstack(e2)
87         systemstack(func() {
88                 x.f = y // ERROR "write barrier prohibited by caller"
89         })
90 }
91
92 func e2() {
93         x.f = y // ERROR "write barrier prohibited by caller"
94 }