golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.03k stars 17.67k forks source link

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

Closed tklauser closed 1 year ago

tklauser commented 1 year ago

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/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.

cuonglm commented 1 year ago

The problem is with inline static init, you can pass -d=inlstaticinit=0 to workaround this issue.

gopherbot commented 1 year ago

Change https://go.dev/cl/465096 mentions this issue: cmd/compile: fix inline static init for constant expression

tklauser commented 1 year ago

@gopherbot please consider this for backport to 1.20, it's a regression.

gopherbot commented 1 year ago

Backport issue(s) opened: #58319 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

gopherbot commented 1 year ago

Change https://go.dev/cl/466277 mentions this issue: cmd/compile: rename EvalConst to EvalExpr

gopherbot commented 1 year ago

Change https://go.dev/cl/467015 mentions this issue: cmd/compile: disable inline static init optimization

gopherbot commented 1 year ago

Change https://go.dev/cl/467016 mentions this issue: cmd/compile: reenable inline static init