Skip to content
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 bounds for & of positive values #38717

Open
bmkessler opened this issue Apr 28, 2020 · 1 comment
Open

cmd/compile: prove bounds for & of positive values #38717

bmkessler opened this issue Apr 28, 2020 · 1 comment

Comments

@bmkessler
Copy link
Contributor

@bmkessler bmkessler commented Apr 28, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Compile

package main

func test(foo []byte, i int) {
	_ = foo[63]
	r := i & 63
	_ = foo[r]
}

func main() {}

go build -gcflags="-d=ssa/check_bce/debug=1"

What did you expect to see?

Just the first bounds check for the initial length of the slice

./test.go:4:9: Found IsInBounds

Because prove should be able to deduce that the masked value is bounded by 63 and so is already in bounds.

r := i&m && m >= 0 --> 0 <= r <= m

What did you see instead?

Both accesses require a bounds check.

./test.go:4:9: Found IsInBounds
./test.go:6:9: Found IsInBounds

This is related to #38476

@rasky @josharian @zdjones

@zdjones
Copy link
Contributor

@zdjones zdjones commented Apr 28, 2020

I think this is because prove doesn't make inferences inolving bitwise operations. I have some CLs I've neglected, to which I could hope to someday add inference over bitwise operations (my employer eliminated our 20% time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.