Skip to content

Commit dd5e9b3

Browse files
committed
cmd/compile: add testcase for #24876
This is still not fixed, the testcase reflects that there are still a few boundchecks. Let's fix the good alternative with an explicit test though. Updates #24876 Change-Id: I4da35eb353e19052bd7b69ea6190a69ced8b9b3d Reviewed-on: https://go-review.googlesource.com/107355 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Giovanni Bajo <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent f02cc88 commit dd5e9b3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/checkbce.go

+29
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
package main
1212

13+
import "encoding/binary"
14+
1315
func f0(a []int) {
1416
a[0] = 1 // ERROR "Found IsInBounds$"
1517
a[0] = 1
@@ -142,6 +144,33 @@ func g4(a [100]int) {
142144
}
143145
}
144146

147+
func decode1(data []byte) (x uint64) {
148+
for len(data) >= 32 {
149+
x += binary.BigEndian.Uint64(data[:8])
150+
x += binary.BigEndian.Uint64(data[8:16])
151+
x += binary.BigEndian.Uint64(data[16:24])
152+
x += binary.BigEndian.Uint64(data[24:32])
153+
data = data[32:]
154+
}
155+
return x
156+
}
157+
158+
func decode2(data []byte) (x uint64) {
159+
// TODO(rasky): this should behave like decode1 and compile to no
160+
// boundchecks. We're currently not able to remove all of them.
161+
for len(data) >= 32 {
162+
x += binary.BigEndian.Uint64(data)
163+
data = data[8:]
164+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
165+
data = data[8:]
166+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
167+
data = data[8:]
168+
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
169+
data = data[8:]
170+
}
171+
return x
172+
}
173+
145174
//go:noinline
146175
func useInt(a int) {
147176
}

0 commit comments

Comments
 (0)