]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.26] cmd/compile: don't drop same register twice
authorkhr@golang.org <khr@golang.org>
Sat, 14 Feb 2026 18:04:13 +0000 (10:04 -0800)
committerDavid Chase <drchase@google.com>
Wed, 25 Feb 2026 19:15:27 +0000 (11:15 -0800)
For instructions that clobber both of their input registers, make
sure we don't clobber the same register twice when both input
registers are the same.

This is rare, but it can happen.

Fixes #77623

Change-Id: I794249cf43a8cc4ab3262055daef9193e2442f73
Reviewed-on: https://go-review.googlesource.com/c/go/+/745621
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
(cherry picked from commit f65692ea562bf24c21ae46854e98584dd4bcc201)
Reviewed-on: https://go-review.googlesource.com/c/go/+/745820
Reviewed-by: Mark Freeman <markfreeman@google.com>
src/cmd/compile/internal/ssa/regalloc.go
test/fixedbugs/issue77604.go [new file with mode: 0644]

index a0257f30641e6ab9b5944b643830fc4ad0182c57..861cf7e01141cc000a5f5d06aebbf7ca7f61b9da 100644 (file)
@@ -1810,7 +1810,7 @@ func (s *regAllocState) regalloc(f *Func) {
                        if regspec.clobbersArg0 {
                                s.freeReg(register(s.f.getHome(args[0].ID).(*Register).num))
                        }
-                       if regspec.clobbersArg1 {
+                       if regspec.clobbersArg1 && !(regspec.clobbersArg0 && s.f.getHome(args[0].ID) == s.f.getHome(args[1].ID)) {
                                s.freeReg(register(s.f.getHome(args[1].ID).(*Register).num))
                        }
 
diff --git a/test/fixedbugs/issue77604.go b/test/fixedbugs/issue77604.go
new file mode 100644 (file)
index 0000000..62857f5
--- /dev/null
@@ -0,0 +1,20 @@
+// compile
+
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 77604: compiler crash when source and destination
+// of copy are the same address.
+
+package p
+
+type T struct {
+       a [192]byte
+}
+
+func f(x *T) {
+       i := any(x)
+       y := i.(*T)
+       *y = *x
+}