Skip to content

Commit 6df3aac

Browse files
committed
cmd/compile: fix offset-generator for storeOneLoad
storeOneLoad decompose Load that is then stored, the offset value must be created on the same block with the Load to be dominated, otherwise, it's unsafe if one does not dominate the other. Fixes #48026 Change-Id: Iee5e6c5d3e1b09862afe4e65f7bcd771b4c57367 Reviewed-on: https://go-review.googlesource.com/c/go/+/345434 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 5afa555 commit 6df3aac

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ func storeOneArg(x *expandState, pos src.XPos, b *Block, locs []*LocalSlot, suff
852852

853853
// storeOneLoad creates a decomposed (one step) load that is then stored.
854854
func storeOneLoad(x *expandState, pos src.XPos, b *Block, source, mem *Value, t *types.Type, offArg, offStore int64, loadRegOffset Abi1RO, storeRc registerCursor) *Value {
855-
from := x.offsetFrom(b, source.Args[0], offArg, types.NewPtr(t))
855+
from := x.offsetFrom(source.Block, source.Args[0], offArg, types.NewPtr(t))
856856
w := source.Block.NewValue2(source.Pos, OpLoad, t, from, mem)
857857
return x.storeArgOrLoad(pos, b, w, mem, t, offStore, loadRegOffset, storeRc)
858858
}

test/fixedbugs/issue48026.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile -d=ssa/check/on
2+
3+
// Copyright 2021 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 p
8+
9+
var i int
10+
11+
type t struct {
12+
a, b, c, d, e int
13+
}
14+
15+
func f(p t, q int) int {
16+
var a, b, c, d, e, f, g int
17+
var h, i, j, k, l, m int
18+
_, _, _, _, _, _, _ = a, b, c, d, e, f, g
19+
_, _, _, _, _, _ = h, i, j, k, l, m
20+
return 0
21+
}
22+
23+
func g() int {
24+
var v t
25+
return f(v, 1<<i)
26+
}

0 commit comments

Comments
 (0)