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
Closed

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

mmacdermaid opened this issue Sep 14, 2017 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mmacdermaid
Copy link

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
Copy link
Contributor

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.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 14, 2017
@davecheney
Copy link
Contributor

davecheney commented Sep 14, 2017 via email

@mmacdermaid
Copy link
Author

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

@davecheney
Copy link
Contributor

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

@gopherbot
Copy link

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

@odeke-em
Copy link
Member

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

@odeke-em odeke-em reopened this Sep 17, 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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants