1
2
3
4
5 package test
6
7 import (
8 "testing"
9 )
10
11 var glob = 3
12 var globp *int64
13
14
15
16
17
18
19
20
21
22
23
24
25 func TestZeroRange(t *testing.T) {
26 testZeroRange8(t)
27 testZeroRange16(t)
28 testZeroRange32(t)
29 testZeroRange64(t)
30 testZeroRange136(t)
31 }
32
33 func testZeroRange8(t *testing.T) (r int64) {
34 defer func() {
35 glob = 4
36 }()
37 globp = &r
38 return
39 }
40
41 func testZeroRange16(t *testing.T) (r, s int64) {
42 defer func() {
43 glob = 4
44 }()
45 globp = &r
46 globp = &s
47 return
48 }
49
50 func testZeroRange32(t *testing.T) (r, s, t2, u int64) {
51 defer func() {
52 glob = 4
53 }()
54 globp = &r
55 globp = &s
56 globp = &t2
57 globp = &u
58 return
59 }
60
61 func testZeroRange64(t *testing.T) (r, s, t2, u, v, w, x, y int64) {
62 defer func() {
63 glob = 4
64 }()
65 globp = &r
66 globp = &s
67 globp = &t2
68 globp = &u
69 globp = &v
70 globp = &w
71 globp = &x
72 globp = &y
73 return
74 }
75
76 func testZeroRange136(t *testing.T) (r, s, t2, u, v, w, x, y, r1, s1, t1, u1, v1, w1, x1, y1, z1 int64) {
77 defer func() {
78 glob = 4
79 }()
80 globp = &r
81 globp = &s
82 globp = &t2
83 globp = &u
84 globp = &v
85 globp = &w
86 globp = &x
87 globp = &y
88 globp = &r1
89 globp = &s1
90 globp = &t1
91 globp = &u1
92 globp = &v1
93 globp = &w1
94 globp = &x1
95 globp = &y1
96 globp = &z1
97 return
98 }
99
100 type S struct {
101 x [2]uint64
102 p *uint64
103 y [2]uint64
104 q uint64
105 }
106
107 type M struct {
108 x [8]uint64
109 p *uint64
110 y [8]uint64
111 q uint64
112 }
113
114 type L struct {
115 x [4096]uint64
116 p *uint64
117 y [4096]uint64
118 q uint64
119 }
120
121
122 func triggerZerorangeLarge(f, g, h uint64) (rv0 uint64) {
123 ll := L{p: &f}
124 da := f
125 rv0 = f + g + h
126 defer func(dl L, i uint64) {
127 rv0 += dl.q + i
128 }(ll, da)
129 return rv0
130 }
131
132
133 func triggerZerorangeMedium(f, g, h uint64) (rv0 uint64) {
134 ll := M{p: &f}
135 rv0 = f + g + h
136 defer func(dm M, i uint64) {
137 rv0 += dm.q + i
138 }(ll, f)
139 return rv0
140 }
141
142
143 func triggerZerorangeSmall(f, g, h uint64) (rv0 uint64) {
144 ll := S{p: &f}
145 rv0 = f + g + h
146 defer func(ds S, i uint64) {
147 rv0 += ds.q + i
148 }(ll, f)
149 return rv0
150 }
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 func TestZerorange45372(t *testing.T) {
174 if r := triggerZerorangeLarge(101, 303, 505); r != 1010 {
175 t.Errorf("large: wanted %d got %d", 1010, r)
176 }
177 if r := triggerZerorangeMedium(101, 303, 505); r != 1010 {
178 t.Errorf("medium: wanted %d got %d", 1010, r)
179 }
180 if r := triggerZerorangeSmall(101, 303, 505); r != 1010 {
181 t.Errorf("small: wanted %d got %d", 1010, r)
182 }
183
184 }
185
View as plain text