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: mis-calculates a constant #11369

Closed
dvyukov opened this issue Jun 23, 2015 · 2 comments
Closed

cmd/compile: mis-calculates a constant #11369

dvyukov opened this issue Jun 23, 2015 · 2 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 23, 2015

For the following program:

package main
var f = 7 / "0"[0]

go tool compile says:

tmp.go:2: constant 1197 overflows byte

Now sure where 1197 came from, but it must be 0 and the program must compile successfully.

go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64

@tzneal
Copy link
Member

tzneal commented Jun 23, 2015

I've looked into this a bit, and that particular value is coming from gc.Umagic:

ord("0") = 48
Umagic(48) = 171 with shift of 5
7 * 171 = 1197

In gc.walkdiv there is different logic used depending on if the divisor is a power of two or not, so it sometimes works:

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

Same root cause as #11358

https://go-review.googlesource.com/11400

@gopherbot
Copy link

CL https://golang.org/cl/11400 mentions this issue.

@rsc rsc closed this as completed in 765c0f3 Jun 26, 2015
@mikioh mikioh added this to the Go1.5 milestone Jun 27, 2015
@golang golang locked and limited conversation to collaborators Jun 27, 2016
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants