Skip to content

Commit 4e6d346

Browse files
randall77prattmic
authored andcommitted
[release-branch.go1.24] cmd/compile: ensure we don't reuse temporary 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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> (cherry picked from commit cc16fb5) Reviewed-on: https://go-review.googlesource.com/c/go/+/652178
1 parent f5c3883 commit 4e6d346

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/cmd/compile/internal/ssa/regalloc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,7 @@ func (s *regAllocState) regalloc(f *Func) {
16701670
}
16711671
tmpReg = s.allocReg(m, &tmpVal)
16721672
s.nospill |= regMask(1) << tmpReg
1673+
s.tmpused |= regMask(1) << tmpReg
16731674
}
16741675

16751676
// Now that all args are in regs, we're ready to issue the value itself.

test/fixedbugs/issue71857.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run
2+
3+
// Copyright 2025 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import "sync/atomic"
10+
11+
//go:noinline
12+
func f(p0, p1, p2, p3, p4, p5, p6, p7 *uint64, a *atomic.Uint64) {
13+
old := a.Or(0xaaa)
14+
*p0 = old
15+
*p1 = old
16+
*p2 = old
17+
*p3 = old
18+
*p4 = old
19+
*p5 = old
20+
*p6 = old
21+
*p7 = old
22+
}
23+
24+
func main() {
25+
a := new(atomic.Uint64)
26+
p := new(uint64)
27+
f(p, p, p, p, p, p, p, p, a)
28+
29+
}

0 commit comments

Comments
 (0)