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

cmd/compile: println(^uint(0)) fails to compile #21887

Closed
mmacdermaid opened this issue Sep 14, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@mmacdermaid
Copy link

commented Sep 14, 2017

What did you do?

https://play.golang.org/p/bIg5Wj5I4Q

In local builds

println(^uint(0))

Is a compile error

constant 18446744073709551615 overflows int64

In local tests and builds it prints -1

func TestOverflow(t *testing.T) {
	asd := ^uint(0)
	println(asd)
}
go test -test.run TestOverflow
-1

What did you expect to see?

4294967295

What did you see instead?

-1

System details

go version go1.9 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mmacdermaid/git/go"
GORACE=""
GOROOT="/home/mmacdermaid/goinstall/go"
GOTOOLDIR="/home/mmacdermaid/goinstall/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build297215887=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.9
uname -sr: Linux 4.4.0-57-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.23-0ubuntu9) stable release version 2.23, by Roland McGrath et al.
gdb --version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

@ianlancetaylor ianlancetaylor changed the title ^uint(0) not yielding correct results cmd/compile: println(^uint(0)) fails to compile Sep 14, 2017

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Sep 14, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 14, 2017

I think the problem is specific to println(^uint(0)). This fails:

package main

func main() {
	println(^uint(0))
}

Replacing println with fmt.Println works fine.

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Sep 14, 2017

@mmacdermaid

This comment has been minimized.

Copy link
Author

commented Sep 15, 2017

👍 Good to know it's just println(). I can confirm using fmt.Println() over here correctly prints the right results.

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Sep 15, 2017

I'm going to close this as there doesn't seem to be an issue. println isn't really part of the language spec, it's just a vestigial part of the bootstrapping process.

https://golang.org/ref/spec#Bootstrapping

@davecheney davecheney closed this Sep 15, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Sep 15, 2017

Change https://golang.org/cl/63971 mentions this issue: cmd/compile: fix print/println when input is uint

@odeke-em

This comment has been minimized.

Copy link
Member

commented Sep 17, 2017

Reopening this as there is a proper/code fix that @anfernee has up for review.

@odeke-em odeke-em reopened this Sep 17, 2017

@gopherbot gopherbot closed this in 4cff104 Sep 26, 2017

@golang golang locked and limited conversation to collaborators Sep 26, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.