diff options
author | Keith Randall <khr@google.com> | 2019-02-06 14:12:36 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-03-18 17:33:38 +0000 |
commit | 2c423f063b137781a97a6a56998a2e3abffc4051 (patch) | |
tree | a77e1513516b655f90c6a9fb12fbc07c9f1e7af1 /src/cmd/compile/internal/ssa/rewriteMIPS64.go | |
parent | b48bda9c6f57ca9a940eac95700485b9640a62e9 (diff) | |
download | go-2c423f063b137781a97a6a56998a2e3abffc4051.tar.gz go-2c423f063b137781a97a6a56998a2e3abffc4051.zip |
cmd/compile,runtime: provide index information on bounds check failure
A few examples (for accessing a slice of length 3):
s[-1] runtime error: index out of range [-1]
s[3] runtime error: index out of range [3] with length 3
s[-1:0] runtime error: slice bounds out of range [-1:]
s[3:0] runtime error: slice bounds out of range [3:0]
s[3:-1] runtime error: slice bounds out of range [:-1]
s[3:4] runtime error: slice bounds out of range [:4] with capacity 3
s[0:3:4] runtime error: slice bounds out of range [::4] with capacity 3
Note that in cases where there are multiple things wrong with the
indexes (e.g. s[3:-1]), we report one of those errors kind of
arbitrarily, currently the rightmost one.
An exhaustive set of examples is in issue30116[u].out in the CL.
The message text has the same prefix as the old message text. That
leads to slightly awkward phrasing but hopefully minimizes the chance
that code depending on the error text will break.
Increases the size of the go binary by 0.5% (amd64). The panic functions
take arguments in registers in order to keep the size of the compiled code
as small as possible.
Fixes #30116
Change-Id: Idb99a827b7888822ca34c240eca87b7e44a04fdd
Reviewed-on: https://go-review.googlesource.com/c/go/+/161477
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteMIPS64.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewriteMIPS64.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS64.go b/src/cmd/compile/internal/ssa/rewriteMIPS64.go index 4d1d817033..ca93e04c2c 100644 --- a/src/cmd/compile/internal/ssa/rewriteMIPS64.go +++ b/src/cmd/compile/internal/ssa/rewriteMIPS64.go @@ -469,6 +469,8 @@ func rewriteValueMIPS64(v *Value) bool { return rewriteValueMIPS64_OpOr8_0(v) case OpOrB: return rewriteValueMIPS64_OpOrB_0(v) + case OpPanicBounds: + return rewriteValueMIPS64_OpPanicBounds_0(v) case OpRound32F: return rewriteValueMIPS64_OpRound32F_0(v) case OpRound64F: @@ -7412,6 +7414,66 @@ func rewriteValueMIPS64_OpOrB_0(v *Value) bool { return true } } +func rewriteValueMIPS64_OpPanicBounds_0(v *Value) bool { + // match: (PanicBounds [kind] x y mem) + // cond: boundsABI(kind) == 0 + // result: (LoweredPanicBoundsA [kind] x y mem) + for { + kind := v.AuxInt + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + mem := v.Args[2] + if !(boundsABI(kind) == 0) { + break + } + v.reset(OpMIPS64LoweredPanicBoundsA) + v.AuxInt = kind + v.AddArg(x) + v.AddArg(y) + v.AddArg(mem) + return true + } + // match: (PanicBounds [kind] x y mem) + // cond: boundsABI(kind) == 1 + // result: (LoweredPanicBoundsB [kind] x y mem) + for { + kind := v.AuxInt + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + mem := v.Args[2] + if !(boundsABI(kind) == 1) { + break + } + v.reset(OpMIPS64LoweredPanicBoundsB) + v.AuxInt = kind + v.AddArg(x) + v.AddArg(y) + v.AddArg(mem) + return true + } + // match: (PanicBounds [kind] x y mem) + // cond: boundsABI(kind) == 2 + // result: (LoweredPanicBoundsC [kind] x y mem) + for { + kind := v.AuxInt + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + mem := v.Args[2] + if !(boundsABI(kind) == 2) { + break + } + v.reset(OpMIPS64LoweredPanicBoundsC) + v.AuxInt = kind + v.AddArg(x) + v.AddArg(y) + v.AddArg(mem) + return true + } + return false +} func rewriteValueMIPS64_OpRound32F_0(v *Value) bool { // match: (Round32F x) // cond: |