go icon indicating copy to clipboard operation
go copied to clipboard

cmd/compile: constant overflows when assigned to package level var (Go 1.20 regression)

Open tklauser opened this issue 1 year ago • 1 comments

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

$ go version
go version go1.20 linux/amd64

Does this issue reproduce with the latest release?

Yes, however it does not reproduce with Go 1.19 or earlier. So this looks like a regression in Go 1.20.

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

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

What did you do?

Some unit tests in the github.com/cilium/cilium/cmd package no longer built with a constant overflow error when being build with Go 1.20. They built fine and passed with Go 1.19 and earlier:

https://github.com/cilium/cilium/actions/runs/4083992015/jobs/7040172384

@ti-mo managed to come up with a minimal reproducer:

https://go.dev/play/p/ClBVgMEVVhG?v=gotip

What did you expect to see?

The reproducer (and the tests in package github.com/cilium/cilium/cmd) to build without errors using Go 1.20.

What did you see instead?

./prog.go:8:30: constant 3476277 overflows uint16
./prog.go:8:30: constant 3476224 overflows uint16

Go build failed.

The error only seems to occur if the result of bits.ReverseBytes16(13579) is assigned to a package level var. It builds fine if the result is assigned e.g. to a func level var.


Thanks to @ti-mo for helping me analyze this error and coming up with a minimal reproducer for playground.

tklauser avatar Feb 03 '23 14:02 tklauser