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: bad walkinrange rewrites on constant above 2**63 #27143
Comments
unit64's legal range should be 0000 0000 0000 0000 ~~ ffff ffff ffff ffff Do I misunderstand something here? |
The constant referenced in the error (
and any literal in the second comparison triggers the error, for example:
works too (but you need a second comparison: just the first doesn't error). Some kind of comparison optimization gone wrong? (but the issue is still there even with |
Simplified version. This works: package main
func main() {
var c uint64
const x, y uint64 = 0xc00921f9f01b866e, 0xc00921ff2e48e8a7
_ = c < y
_ = c > x
_ = c < y || c > x
_ = c < y && c < x
_ = c > y && c > x
_ = c > y && c < x
_ = c < y && c >= x
_ = c <= y && c >= x
} This doesn't (at least since 1.8): package main
func main() {
var c uint64
const x, y uint64 = 0xc00921f9f01b866e, 0xc00921ff2e48e8a7
_ = c < y && c > x // constant -4609115386278082961 overflows uint64
_ = c <= y && c > x // same as above
} |
First one works, the second errors:
When
The rewrite introduces the bad const. I suspect this may be an issue with cc @josharian |
Change https://golang.org/cl/130735 mentions this issue: |
One nuclear option would be to just disable the range check optimization when |
I'm on the fence about whether this fix for this should be backported. Opinions? |
It's the compiler rejecting valid code... even if it's not common to write expressions with integers over 2**63. IMO this should be considered for backporting, at least on 1.11.1. The fix is very simple and it just disables an incorrect optimization, it should be safe to backport. |
Certainly seems to qualify for a backport. |
Yeah. My hesitation was only that this appears to have existed for many releases, and the symptom is a spurious compiler error (not bad code generation). Nevertheless, I agree. @gopherbot please open backport tracking issues. |
Backport issue(s) opened: #27246 (for 1.11), #27247 (for 1.10). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
The below go code is rejected by go1.11.
With error message
But this code is accepted by go1.6 and gccgo.
The text was updated successfully, but these errors were encountered: