New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: prove/BCE don't seem affected by hints that signed integers are not negative #28956

mvdan opened this Issue Nov 26, 2018 · 0 comments


None yet
1 participant

mvdan commented Nov 26, 2018

$ cat f.go
package p

func f(i int, data []byte) {
        if i >= 0 {
                for i < len(data) {
                        _ = data[i] // bounds check!
$ go build -gcflags=-d=ssa/check_bce/debug=1 f.go
# command-line-arguments
./f.go:6:33: Found IsInBounds
$ go version
go version devel +048c9164a0 Sat Nov 24 23:55:07 2018 +0000 linux/amd64

If we make the index an unsigned integer instead of using the if i >= 0 hint, the bounds check goes away.

I haven't found this in real code, but I tried this hint it while trying to remove a bounds check from real code. I was surprised to see that BCE would still not do its thing with the hint. Seems to me like this should be a simple fix somewhere in the prove or BCE passes.

/cc @aclements @rasky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment