-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: unsafe.Add bug when adding uint8 value to a pointer #48536
Comments
This looks like a bug with
But |
I think we just need to convert the |
@randall77 darwin/arm64 does not fail, the generated code:
any idea why? |
x86 has weird legacy semantics for instructions like I'd assume that just doesn't apply to arm64 and instructions there always overwrite the full register. |
@gopherbot Please open a backport issue to Go 1.17. This appears to be a bug in the implementation of |
Backport issue(s) opened: #48561 (for 1.17). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Simplified test case:
|
Change https://golang.org/cl/351592 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
See https://play.golang.org/p/KR_dZZU0BDN. I used
unsafe.Add
in a loop to randomly advance a unsafe.Pointer that points to a byte array. Thelen
argument type isuint8
where value is randomly 0 or 1. Also there's a function that would manipulate the value behind the pointer but it's not used.What did you expect to see?
I expected the program to exit cleanly as the unsafe operations seem valid.
What did you see instead?
SIGSEGV crash for line 22 on the second iteration of the loop because the first
dstNext = unsafe.Add(dstNext, uint8(adv))
seems to store a garbage value todstNext
. Whenlen
is of any other integer type the program exits cleanly. Try changing the line 23 todstNext = unsafe.Add(dstNext, uint16(adv))
. Also removing the unused function makes the program exit cleanly.The text was updated successfully, but these errors were encountered: