-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: "0"[0] should not be a constant #11370
Comments
I've probed around a little and I believe Edit: After looking further into things and understanding a bit about the compile it appears that the code in cgen.go expects |
CL https://golang.org/cl/14800 mentions this issue. |
After digging around for a while I think I found the problem and a potential fix (for my architecture). "0"[0] is converted into a constant during walkexpr, which of course will trigger an error for -"0"[0]; however, codegen expects this to be handled on the front end in the code for agenr
I was able to write code that correctly fixed this by loading the string into a register, and then loading the byte at that correct index but this seemed inefficient since the byte that needs to be loaded is known at compile time. To address this I've added this code to cgen_wb that checks for this case and loads the byte directly into the register. At cgen.go:542
Once I add this code to another place it passes all tests on my architecture and OS. Can I get some feedback before I move further with this fix? Is this approach valid? |
CL https://golang.org/cl/15740 mentions this issue. |
There's a CL pending, but it's scary, and there's no real harm in the current behavior. Leaving for Go 1.7. |
Still scary, still too late. Regrettable that we didn't get to this early in the Go 1.7 cycle. We are going to try to do better next round. |
The following program: http://play.golang.org/p/Xz1-Us2Cwl is rejected with:
/tmp/sandbox748824652/main.go:4: constant -48 overflows uint8
However, indexing a string constant with a constant index does not produce a constant, and thus the program should be valid.
See also #11368.
The text was updated successfully, but these errors were encountered: