Skip to content

Commit 2c6455f

Browse files
committed
fix test
1 parent ab335a6 commit 2c6455f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

test/checkbce.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ func g4(a [100]int) {
136136
useInt(a[i+25])
137137
useInt(a[i+50])
138138

139-
// The following access is out of bounds.
139+
// The following are out of bounds.
140+
if a[0] == 0xdeadbeef {
141+
// This is a trick to prohibit sccp to optimize out the following out of bound check
142+
continue
143+
}
144+
useInt(a[i-11]) // ERROR "Found IsInBounds$"
140145
useInt(a[i+51]) // ERROR "Found IsInBounds$"
141146
}
142147
}

test/loopbce.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ func h2(a []byte) {
201201

202202
func k0(a [100]int) [100]int {
203203
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
206+
continue
207+
}
208+
a[i-11] = i
204209
a[i-10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
205210
a[i-5] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
206211
a[i] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
@@ -213,6 +218,11 @@ func k0(a [100]int) [100]int {
213218

214219
func k1(a [100]int) [100]int {
215220
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
223+
continue
224+
}
225+
useSlice(a[:i-11])
216226
useSlice(a[:i-10]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
217227
useSlice(a[:i-5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
218228
useSlice(a[:i]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
@@ -227,6 +237,11 @@ func k1(a [100]int) [100]int {
227237

228238
func k2(a [100]int) [100]int {
229239
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
242+
continue
243+
}
244+
useSlice(a[i-11:])
230245
useSlice(a[i-10:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
231246
useSlice(a[i-5:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
232247
useSlice(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
@@ -240,6 +255,11 @@ func k2(a [100]int) [100]int {
240255

241256
func k3(a [100]int) [100]int {
242257
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
260+
continue
261+
}
262+
a[i+9] = i
243263
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
244264
a[i+11] = i
245265
}
@@ -248,16 +268,26 @@ func k3(a [100]int) [100]int {
248268

249269
func k3neg(a [100]int) [100]int {
250270
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
273+
continue
274+
}
251275
a[i+9] = i
252276
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
277+
a[i+11] = i
253278
}
254279
return a
255280
}
256281

257282
func k3neg2(a [100]int) [100]int {
258283
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
286+
continue
287+
}
259288
a[i+9] = i
260289
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
290+
a[i+11] = i
261291
}
262292
return a
263293
}

0 commit comments

Comments
 (0)