Skip to content

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

@bmkessler

Description

@bmkessler

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions