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
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 19, 2020

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 self-assigned this Nov 19, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 19, 2020

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.

Loading

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

@mdempsky 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

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 25, 2020

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

Loading

@gopherbot gopherbot closed this in 259fd8a Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants