2 // errorcheck -0 -d=ssa/prove/debug=1
8 func f0a(a []int) int {
10 for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
11 x += a[i] // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
16 func f0b(a []int) int {
18 for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
19 b := a[i:] // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
25 func f0c(a []int) int {
27 for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
28 b := a[:i+1] // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
34 func f1(a []int) int {
36 for _, i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
42 func f2(a []int) int {
44 for i := 1; i < len(a); i++ { // ERROR "Induction variable: limits \[1,\?\), increment 1$"
45 x += a[i] // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
50 func f4(a [10]int) int {
52 for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
53 x += a[i] // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
58 func f5(a [10]int) int {
60 for i := -10; i < len(a); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
66 func f5_int32(a [10]int) int {
68 for i := int32(-10); i < int32(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
74 func f5_int16(a [10]int) int {
76 for i := int16(-10); i < int16(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
82 func f5_int8(a [10]int) int {
84 for i := int8(-10); i < int8(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
91 for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
92 b := a[0:i] // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
97 func g0a(a string) int {
99 for i := 0; i < len(a); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
100 x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
105 func g0b(a string) int {
107 for i := 0; len(a) > i; i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
108 x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
113 func g0c(a string) int {
115 for i := len(a); i > 0; i-- { // ERROR "Induction variable: limits \(0,\?\], increment 1$"
116 x += int(a[i-1]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
121 func g0d(a string) int {
123 for i := len(a); 0 < i; i-- { // ERROR "Induction variable: limits \(0,\?\], increment 1$"
124 x += int(a[i-1]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
129 func g0e(a string) int {
131 for i := len(a) - 1; i >= 0; i-- { // ERROR "Induction variable: limits \[0,\?\], increment 1$"
132 x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
137 func g0f(a string) int {
139 for i := len(a) - 1; 0 <= i; i-- { // ERROR "Induction variable: limits \[0,\?\], increment 1$"
140 x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
148 for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
149 x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
157 for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
159 if a[i] == 'e' { // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
168 a := "this string has length 25"
169 for i := 0; i < len(a); i += 5 { // ERROR "Induction variable: limits \[0,20\], increment 5$"
170 useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
171 useString(a[:i+3]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
172 useString(a[:i+5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
178 for i := 0; i < len(a); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
179 useString(a[i+1:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
184 for i := 0; i < len(a); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
185 useString(a[:i+1]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
191 for i := range c { // ERROR "Induction variable: limits \[0,128\), increment 1$"
192 c[i] = byte(i) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
197 for i := range a[:128] { // ERROR "Induction variable: limits \[0,128\), increment 1$"
202 func k0(a [100]int) [100]int {
203 for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
204 if a[0] == 0xdeadbeef {
205 // This is a trick to prohibit sccp to optimize out the following out of bound check
209 a[i-10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
210 a[i-5] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
211 a[i] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
212 a[i+5] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
213 a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
219 func k1(a [100]int) [100]int {
220 for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
221 if a[0] == 0xdeadbeef {
222 // This is a trick to prohibit sccp to optimize out the following out of bound check
226 useSlice(a[:i-10]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
227 useSlice(a[:i-5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
228 useSlice(a[:i]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
229 useSlice(a[:i+5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
230 useSlice(a[:i+10]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
231 useSlice(a[:i+11]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
238 func k2(a [100]int) [100]int {
239 for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
240 if a[0] == 0xdeadbeef {
241 // This is a trick to prohibit sccp to optimize out the following out of bound check
245 useSlice(a[i-10:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
246 useSlice(a[i-5:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
247 useSlice(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
248 useSlice(a[i+5:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
249 useSlice(a[i+10:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
250 useSlice(a[i+11:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
256 func k3(a [100]int) [100]int {
257 for i := -10; i < 90; i++ { // ERROR "Induction variable: limits \[-10,90\), increment 1$"
258 if a[0] == 0xdeadbeef {
259 // This is a trick to prohibit sccp to optimize out the following out of bound check
263 a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
269 func k3neg(a [100]int) [100]int {
270 for i := 89; i > -11; i-- { // ERROR "Induction variable: limits \(-11,89\], increment 1$"
271 if a[0] == 0xdeadbeef {
272 // This is a trick to prohibit sccp to optimize out the following out of bound check
276 a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
282 func k3neg2(a [100]int) [100]int {
283 for i := 89; i >= -10; i-- { // ERROR "Induction variable: limits \[-10,89\], increment 1$"
284 if a[0] == 0xdeadbeef {
285 // This is a trick to prohibit sccp to optimize out the following out of bound check
289 a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
295 func k4(a [100]int) [100]int {
297 for i := min; i < min+50; i++ { // ERROR "Induction variable: limits \[-9223372036854775808,-9223372036854775758\), increment 1$"
298 a[i-min] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
303 func k5(a [100]int) [100]int {
305 for i := max - 50; i < max; i++ { // ERROR "Induction variable: limits \[9223372036854775757,9223372036854775807\), increment 1$"
306 a[i-max+50] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
307 a[i-(max-70)] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
312 func d1(a [100]int) [100]int {
313 for i := 0; i < 100; i++ { // ERROR "Induction variable: limits \[0,100\), increment 1$"
314 for j := 0; j < i; j++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
315 a[j] = 0 // ERROR "Proved IsInBounds$"
316 a[j+1] = 0 // FIXME: this boundcheck should be eliminated
323 func d2(a [100]int) [100]int {
324 for i := 0; i < 100; i++ { // ERROR "Induction variable: limits \[0,100\), increment 1$"
325 for j := 0; i > j; j++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
326 a[j] = 0 // ERROR "Proved IsInBounds$"
327 a[j+1] = 0 // FIXME: this boundcheck should be eliminated
334 func d3(a [100]int) [100]int {
335 for i := 0; i <= 99; i++ { // ERROR "Induction variable: limits \[0,99\], increment 1$"
336 for j := 0; j <= i-1; j++ {
338 a[j+1] = 0 // ERROR "Proved IsInBounds$"
346 for i := int64(math.MaxInt64 - 9); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775802\], increment 4$"
349 for i := int64(math.MaxInt64 - 8); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775803\], increment 4$"
352 for i := int64(math.MaxInt64 - 7); i < math.MaxInt64-2; i += 4 {
355 for i := int64(math.MaxInt64 - 6); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775801,9223372036854775801\], increment 4$"
358 for i := int64(math.MaxInt64 - 9); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775802\], increment 4$"
361 for i := int64(math.MaxInt64 - 8); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775803\], increment 4$"
364 for i := int64(math.MaxInt64 - 7); i <= math.MaxInt64-2; i += 4 {
367 for i := int64(math.MaxInt64 - 6); i <= math.MaxInt64-2; i += 4 {
373 for i := int64(math.MinInt64 + 9); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775803,-9223372036854775799\], increment 4"
376 for i := int64(math.MinInt64 + 8); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775804,-9223372036854775800\], increment 4"
379 for i := int64(math.MinInt64 + 7); i > math.MinInt64+2; i -= 4 {
382 for i := int64(math.MinInt64 + 6); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775802,-9223372036854775802\], increment 4"
385 for i := int64(math.MinInt64 + 9); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775803,-9223372036854775799\], increment 4"
388 for i := int64(math.MinInt64 + 8); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775804,-9223372036854775800\], increment 4"
391 for i := int64(math.MinInt64 + 7); i >= math.MinInt64+2; i -= 4 {
394 for i := int64(math.MinInt64 + 6); i >= math.MinInt64+2; i -= 4 {
400 // tests overflow of max-min
401 a := int64(9223372036854774057)
406 panic("invalid test: modulos should differ")
409 for i := b; i < a; i += z { // ERROR "Induction variable: limits \[-1547,9223372036854772720\], increment 1337"
414 func nobce2(a string) {
415 for i := int64(0); i < int64(len(a)); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
416 useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
418 for i := int64(0); i < int64(len(a))-31337; i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
419 useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
421 for i := int64(0); i < int64(len(a))+int64(-1<<63); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
422 useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
424 j := int64(len(a)) - 123
425 for i := int64(0); i < j+123+int64(-1<<63); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
426 useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
428 for i := int64(0); i < j+122+int64(-1<<63); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
429 // len(a)-123+122+MinInt overflows when len(a) == 0, so a bound check is needed here
434 func nobce3(a [100]int64) [100]int64 {
435 min := int64((-1) << 63)
436 max := int64((1 << 63) - 1)
437 for i := min; i < max; i++ { // ERROR "Induction variable: limits \[-9223372036854775808,9223372036854775807\), increment 1$"
442 func issue26116a(a []int) {
443 // There is no induction variable here. The comparison is in the wrong direction.
444 for i := 3; i > 6; i++ {
447 for i := 7; i < 3; i-- {
452 func stride1(x *[7]int) int {
454 for i := 0; i <= 8; i += 3 { // ERROR "Induction variable: limits \[0,6\], increment 3"
455 s += x[i] // ERROR "Proved IsInBounds"
460 func stride2(x *[7]int) int {
462 for i := 0; i < 9; i += 3 { // ERROR "Induction variable: limits \[0,6\], increment 3"
463 s += x[i] // ERROR "Proved IsInBounds"
469 func useString(a string) {
473 func useSlice(a []int) {