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: invalid pointer found on stack when compiled with -race #63657
Comments
Seems to only affect 1.21.x, I was unable to reproduce it in 1.20 or tip. Reproduced on both darwin/arm64 and linux/amd64 This message in the stacktrace caught my attention: |
cc @golang/compiler |
@mauri870 CL https://go.dev/cl/531815 fixes the "unexpected SPWRITE" message. But that is just a message, unrelated to the original bad pointer bug. |
That sounded like a red herring, thanks for clarifying it. |
The program starts failing since https://go-review.googlesource.com/c/go/+/270940, then "fixed" after https://go-review.googlesource.com/c/go/+/517775 Kindly cc @randall77 and @mdempsky to decide what should we do. |
This looks like a bad reordering of a nil pointer check and subsequent pointer arithmetic.
start a write barrier to initialize new object allocated above.
Write barrier is done here, now to do the actual write. But first there are some other instructions!
These 2 instructions are the actual write.
Some uninteresting stuff follows.
The nil pointer check of the result of
Then we actually read
|
Reminds me of #42673, which is what CL 270940 was supposed to fix, not cause. Somehow the nil check just isn't getting the priority it needs to come before the address calculation Here's a reproducer. At least, you can see the problem in assembly. (It will need a wrapper to make it into a test.)
When compiled (no
Note the The trick with the |
@gopherbot Please open a backport issue for 1.21. |
Backport issue(s) opened: #63743 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/537775 mentions this issue: |
Change https://go.dev/cl/538595 mentions this issue: |
Update #63657 Update #45573 Change-Id: I163c6038c13d974dc0ca9f02144472bc05331826 Reviewed-on: https://go-review.googlesource.com/c/go/+/538595 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, as of this writing "go1.21.3".
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run
go test -race .
in this go module.I couldn't reproduce it without dependencies, but the code is quiet small. I'm only "using" Ginkgo and Gomega. Of another dependency I'm just using a type which only ever set to
nil
. I've added some comments.The error only occurs in Go 1.21. Go 1.20 works fine. Also the
-race
flag is required.When I remove dead code the panic doesn't occur.
What did you expect to see?
Ginkgo test results.
What did you see instead?
The text was updated successfully, but these errors were encountered: