Skip to content

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

Closed
@gopherbot

Description

@gopherbot

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickApprovedUsed during the release process for point releasescompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions