-
Notifications
You must be signed in to change notification settings - Fork 18k
gccgo: incorrect order of evaluation #26495
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
Labels
Milestone
Comments
related: #24448 |
Change https://golang.org/cl/125299 mentions this issue: |
Change https://golang.org/cl/125301 mentions this issue: |
hubot
pushed a commit
to gcc-mirror/gcc
that referenced
this issue
Jul 20, 2018
In remove_shortcuts, the shortcut expressions (&&, ||) are rewritten to if statements, which are lifted out before the statement containing the shortcut expression. If the containing statement has other (sub)expressions that should be evaluated before the shortcut expression, which has not been lifted out, this will result in wrong evaluation order. For example, F() + G(A() && B()), the evaluation order per spec is F, A, B (if A returns true), G. If we lift A() and B() out first, they will be called before F, which is wrong. To fix this, we split order_evaluations to two phases. The first phase, which runs before remove_shortcuts, skips shortcut expressions' components. So it won't lift out subexpressions that are evaluated conditionally. The shortcut expression itself is ordered, since it may have side effects. Then we run remove_shortcuts. At this point the subexpressions that should be evaluated before the shortcut expression are already lifted out. remove_shortcuts also runs the second phase of order_evaluations to order the components of shortcut expressions, which were skipped during the first phase. Reorder the code blocks of remove_shortcuts and order_evaluations, since remove_shortcuts now calls Order_eval. Fixes golang/go#26495. Reviewed-on: https://go-review.googlesource.com/125299 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@262908 138bc75d-0d04-0410-961f-82ee72b054a4
gopherbot
pushed a commit
that referenced
this issue
Jul 20, 2018
Gccgo produced incorrect order of evaluation for expressions involving &&, || subexpressions. The fix is CL 125299. Updates #26495. Change-Id: I18d873281709f3160b3e09f0b2e46f5c120e1cab Reviewed-on: https://go-review.googlesource.com/125301 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
This program should print
0
. When built with current gccgo, it prints1
.The immediate problem is that the convert_shortcuts pass moves the function calls to
FV1
andFV2
out of line so that they are executed before the call toF
.CC @cherrymui @thanm
The text was updated successfully, but these errors were encountered: