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

x/build: passing a const to a function which << it causes go1.20 to error in some contexts but not others. go1.19 didn't error. #58316

Closed
nsd20463 opened this issue Feb 4, 2023 · 1 comment
Labels
Builders x/build issues (builders, bots, dashboards) FrozenDueToAge
Milestone

Comments

@nsd20463
Copy link
Contributor

nsd20463 commented Feb 4, 2023

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, and only with 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/ndade/.cache/go-build"
GOENV="/home/ndade/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ndade/go/pkg/mod"
GOOS="linux"
GOPATH="/home/ndade/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ndade/src/go/go1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ndade/src/go/go1.20/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build4124545679=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I passed a const to a function which leftshifts the argument so that non-zero bits drop off the top of the value.
https://go.dev/play/p/LcFGn7DXuJ8
illustrates the problem. If I call swap(const) to initialize a global, the go1.20 compiler complains and fails. If I call swap(const) to initialize a local then go 1.20 compiles the code and it runs properly.

What did you expect to see?

The go 1.19 and earlier compilers compiled this code successfully. However the go 1.20 compiler complains about the calculation of X, the global, but not Y, the local.

What did you see instead?

Go 1.20 compiler errors, complaining that the result of the << overflows uint16. Which it does, but x, the argument to the << is also a uint16. So I don't think the compiler should be complaining at all, and if this is some change in go1.20, I think it should complain consistently in both cases.

@gopherbot gopherbot added the Builders x/build issues (builders, bots, dashboards) label Feb 4, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 4, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 4, 2023

Duplicated of #58293

@cuonglm cuonglm closed this as completed Feb 4, 2023
@golang golang locked and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Builders x/build issues (builders, bots, dashboards) FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants