-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Invalid code generated using atomic #18579
Comments
@stuartcarnie, is this a regression from Go 1.7? /cc @randall77 |
@stuartcarnie the code in that playground link never calls Pop. Is that link wrong/old somehow? |
@randall77 my mistake (copy / paste error); I've updated the link |
Incidentally, this also works, by ensuring |
@bradfitz it is not a regression, as it fails in the playground too |
Here is a smaller repro:
I don't think this is actually a bug. Converting an unsafe.Pointer to a uintptr is asking for all kinds of trouble. We guarantee that this conversion works only if you immediately (before any safepoint) convert back, like I believe the correct answer for your problem is to use
That works. |
@randall77 I notice that I realize this is an implementation detail and it could be considered being pedantic, but any chance those will become intrinsic also? |
They would need a write barrier (already a function call) anyway. |
Ahh, I thought the compiler emitted a check for |
Perhaps they could be intrinsified a bit as:
That'd make the wb-disabled case a bit faster at the cost of increased code size. Not sure how much it'd help or whether the trade-off is worth it. |
Also, if the result of the swap is stored somewhere, then the swap itself should be GC-neutral, since both pointers are stored somewhere before and after. That might be a bit too fiddly, though. |
@josharian, @stuartcarnie, feel free to file a tracking bug at least. Closed bugs aren't the best place to discuss. |
We could intrinsify them so that in the common case that the write barrier is off, they would be a test/branch/store. Could be done, but I don't think it's high on anyone's priority list. |
apologies @bradfitz – do you mean a separate tracking bug for intrinsic support of |
Yes. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8beta2 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/nulQCpZ2nn
What did you expect to see?
I expected
1
fromPop
What did you see instead?
In the case of the playground,
0
. Fromgo 1.8
a segfault due to an invalid pointer. By switching theatomic.StoreUintptr
withprev.next = n
inPush
, the issue goes away.Generated assembly reveals it may be an issue with compiler not recognizing that
n
escapes thePush
functionThe text was updated successfully, but these errors were encountered: