diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index a0257f3064..861cf7e011 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -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 index 0000000000..62857f57f0 --- /dev/null +++ b/test/fixedbugs/issue77604.go @@ -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 +}