blob: d176e28b5ae3fd204398d703005f06f05fcbe43e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// errorcheck -+ -p=runtime
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test go:nowritebarrier and related directives.
// This must appear to be in package runtime so the compiler
// recognizes "systemstack".
package runtime
type t struct {
f *t
}
var x t
var y *t
//go:nowritebarrier
func a1() {
x.f = y // ERROR "write barrier prohibited"
a2() // no error
}
//go:noinline
func a2() {
x.f = y
}
//go:nowritebarrierrec
func b1() {
b2()
}
//go:noinline
func b2() {
x.f = y // ERROR "write barrier prohibited by caller"
}
// Test recursive cycles through nowritebarrierrec and yeswritebarrierrec.
//go:nowritebarrierrec
func c1() {
c2()
}
//go:yeswritebarrierrec
func c2() {
c3()
}
func c3() {
x.f = y
c4()
}
//go:nowritebarrierrec
func c4() {
c2()
}
//go:nowritebarrierrec
func d1() {
d2()
}
func d2() {
d3()
}
//go:noinline
func d3() {
x.f = y // ERROR "write barrier prohibited by caller"
d4()
}
//go:yeswritebarrierrec
func d4() {
d2()
}
//go:noinline
func systemstack(func()) {}
//go:nowritebarrierrec
func e1() {
systemstack(e2)
systemstack(func() {
x.f = y // ERROR "write barrier prohibited by caller"
})
}
func e2() {
x.f = y // ERROR "write barrier prohibited by caller"
}
|