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: constant expression overflow doesn't report an error #42732

Closed
griesemer opened this issue Nov 19, 2020 · 3 comments
Closed

cmd/compile: constant expression overflow doesn't report an error #42732

griesemer opened this issue Nov 19, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@griesemer
Copy link
Contributor

https://play.golang.org/p/Ro-SJWdCh35

The compiler reports an error if a constant literal is too large to represent, but it doesn't if we exceed that value in constant arithmetic.

@griesemer griesemer added this to the Go1.17 milestone Nov 19, 2020
@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 19, 2020
@griesemer griesemer self-assigned this Nov 19, 2020
@mdempsky
Copy link
Member

It looks like we incorrectly allow infinity as a constant, but we correctly error about any attempts to turn it into a typed value.

I think my CLs to switch cmd/compile to use go/constant should fix this.

@mdempsky mdempsky self-assigned this Nov 25, 2020
@mdempsky
Copy link
Member

mdempsky commented Nov 25, 2020

At tip (of dev.regabi) we now ICE instead, because of the failure to report an error message.

Relatedly, I realized I missed that XOR can also cause overflow, so this currently ICEs as well while trying to report the overflow error:

const MaxInt512 = (1<<256 - 1) * (1<<256 + 1)
const _ = ^MaxInt512 // computes -1 << 512

@gopherbot
Copy link

Change https://golang.org/cl/272928 mentions this issue: [dev.regabi] cmd/compile: fix reporting of overflow

@golang golang locked and limited conversation to collaborators Feb 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants