Debian Codegraph @

test/codegen/writebarrier.go

raw
1 // asmcheck
2
3 // Copyright 2023 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 package codegen
8
9 func combine2string(p *[2]string, a, b string) {
10 // amd64:`.*runtime[.]gcWriteBarrier4\(SB\)`
11 // arm64:`.*runtime[.]gcWriteBarrier4\(SB\)`
12 p[0] = a
13 // amd64:-`.*runtime[.]gcWriteBarrier`
14 // arm64:-`.*runtime[.]gcWriteBarrier`
15 p[1] = b
16 }
17
18 func combine4string(p *[4]string, a, b, c, d string) {
19 // amd64:`.*runtime[.]gcWriteBarrier8\(SB\)`
20 // arm64:`.*runtime[.]gcWriteBarrier8\(SB\)`
21 p[0] = a
22 // amd64:-`.*runtime[.]gcWriteBarrier`
23 // arm64:-`.*runtime[.]gcWriteBarrier`
24 p[1] = b
25 // amd64:-`.*runtime[.]gcWriteBarrier`
26 // arm64:-`.*runtime[.]gcWriteBarrier`
27 p[2] = c
28 // amd64:-`.*runtime[.]gcWriteBarrier`
29 // arm64:-`.*runtime[.]gcWriteBarrier`
30 p[3] = d
31 }
32
33 func combine2slice(p *[2][]byte, a, b []byte) {
34 // amd64:`.*runtime[.]gcWriteBarrier4\(SB\)`
35 // arm64:`.*runtime[.]gcWriteBarrier4\(SB\)`
36 p[0] = a
37 // amd64:-`.*runtime[.]gcWriteBarrier`
38 // arm64:-`.*runtime[.]gcWriteBarrier`
39 p[1] = b
40 }
41
42 func combine4slice(p *[4][]byte, a, b, c, d []byte) {
43 // amd64:`.*runtime[.]gcWriteBarrier8\(SB\)`
44 // arm64:`.*runtime[.]gcWriteBarrier8\(SB\)`
45 p[0] = a
46 // amd64:-`.*runtime[.]gcWriteBarrier`
47 // arm64:-`.*runtime[.]gcWriteBarrier`
48 p[1] = b
49 // amd64:-`.*runtime[.]gcWriteBarrier`
50 // arm64:-`.*runtime[.]gcWriteBarrier`
51 p[2] = c
52 // amd64:-`.*runtime[.]gcWriteBarrier`
53 // arm64:-`.*runtime[.]gcWriteBarrier`
54 p[3] = d
55 }
56
57 func trickyWriteNil(p *int, q **int) {
58 if p == nil {
59 // We change "= p" to "= 0" in the prove pass, which
60 // means we have one less pointer that needs to go
61 // into the write barrier buffer.
62 // amd64:`.*runtime[.]gcWriteBarrier1`
63 *q = p
64 }
65 }
66
67 type S struct {
68 a, b string
69 c *int
70 }
71
72 var g1, g2 *int
73
74 func issue71228(dst *S, ptr *int) {
75 // Make sure that the non-write-barrier write.
76 // "sp.c = ptr" happens before the large write
77 // barrier "*dst = *sp". We approximate testing
78 // that by ensuring that two global variable write
79 // barriers aren't combined.
80 _ = *dst
81 var s S
82 sp := &s
83 //amd64:`.*runtime[.]gcWriteBarrier1`
84 g1 = nil
85 sp.c = ptr // outside of any write barrier
86 //amd64:`.*runtime[.]gcWriteBarrier1`
87 g2 = nil
88 //amd64:`.*runtime[.]wbMove`
89 *dst = *sp
90 }
91
92 func writeDouble(p *[2]*int, x, y *int) {
93 // arm64: `LDP\s`, `STP\s\(R[0-9]+, R[0-9]+\), \(`,
94 p[0] = x
95 // arm64: `STP\s\(R[0-9]+, R[0-9]+\), 16\(`,
96 p[1] = y
97 }
98
99 func writeDoubleNil(p *[2]*int) {
100 // arm64: `LDP\s`, `STP\s\(R[0-9]+, R[0-9]+\),`, `STP\s\(ZR, ZR\),`
101 p[0] = nil
102 p[1] = nil
103 }