diff options
author | Keith Randall <khr@golang.org> | 2017-10-25 13:46:38 -0700 |
---|---|---|
committer | Andrew Bonventre <andybons@golang.org> | 2018-01-22 20:24:55 +0000 |
commit | 5c08eef8706d56fe9509e9bca63d6a7f9d395036 (patch) | |
tree | 3aa697a23a1deae00216e4f43405f913d5e570c2 | |
parent | aae9998d41d1890476951ef5ae51adc1d4a5e1d7 (diff) | |
download | go-5c08eef8706d56fe9509e9bca63d6a7f9d395036.tar.gz go-5c08eef8706d56fe9509e9bca63d6a7f9d395036.zip |
[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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/88317
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
-rw-r--r-- | src/cmd/compile/internal/x86/387.go | 6 | ||||
-rw-r--r-- | test/fixedbugs/issue22429.go | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/x86/387.go b/src/cmd/compile/internal/x86/387.go index cdac000648..7a3622405c 100644 --- a/src/cmd/compile/internal/x86/387.go +++ b/src/cmd/compile/internal/x86/387.go @@ -46,6 +46,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { case ssa.Op386MOVSSloadidx1, ssa.Op386MOVSDloadidx1: p.From.Scale = 1 p.From.Index = v.Args[1].Reg() + if p.From.Index == x86.REG_SP { + p.From.Reg, p.From.Index = p.From.Index, p.From.Reg + } case ssa.Op386MOVSSloadidx4: p.From.Scale = 4 p.From.Index = v.Args[1].Reg() @@ -95,6 +98,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { case ssa.Op386MOVSSstoreidx1, ssa.Op386MOVSDstoreidx1: p.To.Scale = 1 p.To.Index = v.Args[1].Reg() + if p.To.Index == x86.REG_SP { + p.To.Reg, p.To.Index = p.To.Index, p.To.Reg + } case ssa.Op386MOVSSstoreidx4: p.To.Scale = 4 p.To.Index = v.Args[1].Reg() diff --git a/test/fixedbugs/issue22429.go b/test/fixedbugs/issue22429.go new file mode 100644 index 0000000000..289b434a74 --- /dev/null +++ b/test/fixedbugs/issue22429.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2017 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. + +// Make sure SSA->assembly pass can handle SP as an index register. + +package p + +type T struct { + a,b,c,d float32 +} + +func f(a *[8]T, i,j,k int) float32 { + b := *a + return b[i].a + b[j].b + b[k].c +} |