Skip to content
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: nil dereference when storing field of non-nil struct value [1.24 backport] #71904

Open
gopherbot opened this issue Feb 22, 2025 · 0 comments
Labels
CherryPickCandidate 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPickCandidate 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

1 participant