-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: == and != comparisons of addresses of symbols not handled consistently #24503
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
Comments
Change https://golang.org/cl/102275 mentions this issue: |
I don't think this is a bug.
I admit that it's a bit weird that they are both equal and not equal at the same time. But a valid program should not be relying on the result in any case. That said, I'm not adverse to the fix you suggested. It seems harmless enough. |
I have read that line in the language spec, but have always understood it as saying that the equality may change from one Go release to the next; I didn't think of it as possibly causing inconsistent behaviour. The risk is that a program using an imported type may not necessarily know that the type is zero-width, and could be surprised by this behaviour. Alternatively, instead of treating this as a bug fix, it could be considered an improvement to CL 38338, by optimizing the other kind of comparison as well. |
I guess, although I think |
I think this assumption is similar to the one that |
I'll weigh in for team bug. The spec defines I argue this is a bug because it violates this constraint. This program should either print I acknowledge the spec could be more precise in its description of comparing pointers to zero-width variables, but I think the simplest interpretation is that "equal" and "not equal" are exclusive relations that hold indefinitely for any two values. I think if we really wanted to admit the current behavior, we should revise the spec to explicitly state that results may by different for each comparison (of pointer to zero-width variables). |
What version of Go are you using (
go version
)?1.9, 1.10, tip
Does this issue reproduce with the latest release?
Yes, but not with 1.8 or older releases.
What operating system and processor architecture are you using (
go env
)?linux amd64
What did you do?
https://play.golang.org/p/KyovZxzxQfS
What did you expect to see?
Either "equal" or "unequal" should be printed. Go 1.8 printed "equal".
What did you see instead?
No output.
It seems that the problem is caused by CL 38338, which added a SSA rule to simplify a comparison of the addresses of two symbols (even when those addresses are numerically identical):
However, the negated form of this rule is missing, so the compiler still emits a numeric comparison of the two addresses for the second comparison in the code. Adding this rule optimizes away that comparison and fixes the program output (to "unequal"):
The text was updated successfully, but these errors were encountered: