-
Notifications
You must be signed in to change notification settings - Fork 18k
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: _ = 1/x optimized away even though 1/x may panic #8613
Comments
if i use _ = f(), then f() is actually called, so I'd expect 5/(1-v) to be also evaluated (and panic) for consistency. http://play.golang.org/p/qPMDjks3So |
The spec doesn't say that assignments to _ can be "optimized away". It's an assignment like any other. It just says that the value, once assigned to a _, cannot be recovered from the _. That said, perhaps we should be more explicit about it, An implementation is free to optimize as much as it wants as long as there's no semantic change. If an expression panics upon evaluation, it needs to keep panicking after the optimization. I believe we've had issues with this in the past (_ = f()). I'd say this is an implementation bug. Always good to check what gccgo does. |
So division can be skipped, but slicing out of bounds seems to still panic: http://play.golang.org/p/VISwXHnZQ_ func main() { defer func() { if e := recover(); e != nil { println("Panic") } }() i := 1 s := make([]byte, i + 1) _ = 1 + s[5] println("No panic") } |
Looks like a bug in gc to me: http://play.golang.org/p/B3T7Wt8GFq division appears to be ignored as possible source of panics when it comes to the check whether the rhs can be "optimized away". Changing to a compiler bug. Labels changed: added release-none, repo-main. Owner changed to ---. Status changed to Accepted. |
Does anybody know whether this has been fixed? |
This is fixed in the SSA backend. It is not fixed for the legacy compiler (aka all the other architectures besides amd64). |
Doesn't look like it's fixed:
runs w/o complaints. |
Cool. You know where the tests for it are?
|
I don't think there are any. It was fixed by happenstance, not deliberately. We could add a +build amd64 test. |
@griesemer that program does panic for me at tip. |
@griesemer, yeah... I see it correctly failing at tip:
|
CL https://golang.org/cl/21325 mentions this issue. |
My apologies. I thought I had an updated build but obviously I didn't (at home). |
The text was updated successfully, but these errors were encountered: