Skip to content

cmd/compile: nil dereference when storing field of non-nil struct value [1.24 backport] #71904

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

Closed
gopherbot opened this issue Feb 22, 2025 · 3 comments
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@gopherbot
Copy link
Contributor

@randall77 requested issue #71857 to be considered for backport to the next 1.24 minor release.

Ok, thanks for the reproducer.

This looks like a bug in the register allocator when compiling (*rw).closerecvsend, where it uses the same register for two different things simultaneously. Those two things being the value being compare-and-swapped (0b1100), and the this argument. That's where the 0xc pointer comes from.

I think I have a 1-line fix.

diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go
index 1b7bcb2b1d..d794098b9d 100644
--- a/src/cmd/compile/internal/ssa/regalloc.go
+++ b/src/cmd/compile/internal/ssa/regalloc.go
@@ -1677,6 +1677,7 @@ func (s *regAllocState) regalloc(f *Func) {
                                }
                                tmpReg = s.allocReg(m, &tmpVal)
                                s.nospill |= regMask(1) << tmpReg
+                               s.tmpused |= regMask(1) << tmpReg
                        }
 
                        // Now that all args are in regs, we're ready to issue the value itself.

I still need to figure out a reasonable test for it.

@gopherbot please open a backport issue for 1.24.

@gopherbot gopherbot added the CherryPickCandidate Used during the release process for point releases label Feb 22, 2025
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 22, 2025
@gopherbot gopherbot added this to the Go1.24.1 milestone Feb 22, 2025
@gopherbot
Copy link
Contributor Author

Change https://go.dev/cl/652178 mentions this issue: [release-branch.go1.24] cmd/compile: ensure we don't reuse temporary register

@randall77 randall77 added the Critical A critical problem that affects the availability or correctness of production systems built using Go label Feb 25, 2025
@prattmic prattmic added the CherryPickApproved Used during the release process for point releases label Feb 26, 2025
@gopherbot gopherbot removed the CherryPickCandidate Used during the release process for point releases label Feb 26, 2025
@dmitshur dmitshur added CherryPickCandidate Used during the release process for point releases and removed CherryPickApproved Used during the release process for point releases Critical A critical problem that affects the availability or correctness of production systems built using Go labels Feb 26, 2025
@dmitshur
Copy link
Contributor

dmitshur commented Feb 26, 2025

Removed Critical label here since it only applies to upstream issues, and #71857 already has it.

@dmitshur dmitshur added CherryPickApproved Used during the release process for point releases and removed CherryPickCandidate Used during the release process for point releases labels Feb 26, 2025
gopherbot pushed a commit that referenced this issue Feb 26, 2025
…register

Before this CL, we could use the same register for both a temporary
register and for moving a value in the output register out of the way.

Fixes #71904

Change-Id: Iefbfd9d4139136174570d8aadf8a0fb391791ea9
Reviewed-on: https://go-review.googlesource.com/c/go/+/651221
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit cc16fb5)
Reviewed-on: https://go-review.googlesource.com/c/go/+/652178
@gopherbot
Copy link
Contributor Author

Closed by merging CL 652178 (commit 4e6d346) to release-branch.go1.24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

4 participants