Skip to content

cmd/compile: Prove doesn't understand division of slice length #57077

@Nigma1337

Description

@Nigma1337

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

$ go version
go version go1.19.3 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/magnus/.cache/go-build"
GOENV="/home/magnus/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/magnus/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/magnus/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/magnus/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1748103025=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I took the length of an object, to split it into halves, and there were IsSliceInBounds checks

What did you expect to see?

The IsSliceInBounds checks eliminatied

What did you see instead?

They were not eliminated

Short program showing issue

package main

func SplitInHalf(s []int) (left, right []int) {
	middle := len(s) / 2
	left = s[:middle]
	right = s[middle:]
	return
}

func main() {}

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

command-line-arguments

./main.go:5:10: Found IsSliceInBounds
./main.go:6:11: Found IsSliceInBounds

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions