Skip to content

Commit 5c08eef

Browse files
randall77andybons
authored andcommitted
[release-branch.go1.9] cmd/compile: make sure not to use SP as an index register
...because that's an illegal addressing mode. I double-checked handling of this code, and 387 is the only place where this check is missing. Fixes #22429 Change-Id: I2284fe729ea86251c6af2f04076ddf7a5e66367c Reviewed-on: https://go-review.googlesource.com/73551 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-on: https://go-review.googlesource.com/88317 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent aae9998 commit 5c08eef

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/cmd/compile/internal/x86/387.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
4646
case ssa.Op386MOVSSloadidx1, ssa.Op386MOVSDloadidx1:
4747
p.From.Scale = 1
4848
p.From.Index = v.Args[1].Reg()
49+
if p.From.Index == x86.REG_SP {
50+
p.From.Reg, p.From.Index = p.From.Index, p.From.Reg
51+
}
4952
case ssa.Op386MOVSSloadidx4:
5053
p.From.Scale = 4
5154
p.From.Index = v.Args[1].Reg()
@@ -95,6 +98,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
9598
case ssa.Op386MOVSSstoreidx1, ssa.Op386MOVSDstoreidx1:
9699
p.To.Scale = 1
97100
p.To.Index = v.Args[1].Reg()
101+
if p.To.Index == x86.REG_SP {
102+
p.To.Reg, p.To.Index = p.To.Index, p.To.Reg
103+
}
98104
case ssa.Op386MOVSSstoreidx4:
99105
p.To.Scale = 4
100106
p.To.Index = v.Args[1].Reg()

test/fixedbugs/issue22429.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile
2+
3+
// Copyright 2017 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+
// Make sure SSA->assembly pass can handle SP as an index register.
8+
9+
package p
10+
11+
type T struct {
12+
a,b,c,d float32
13+
}
14+
15+
func f(a *[8]T, i,j,k int) float32 {
16+
b := *a
17+
return b[i].a + b[j].b + b[k].c
18+
}

0 commit comments

Comments
 (0)