mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00
cmd/compile: fix bounds check report
For constant-index, variable length situations. Inadvertant shadowing of the yVal variable. Oops. Fixes #75327 Change-Id: I3403066fc39b7664222a3098cf0f22b5761ea66a Reviewed-on: https://go-review.googlesource.com/c/go/+/702015 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
6447ff409a
commit
af03343f93
11 changed files with 43 additions and 10 deletions
|
@ -1306,7 +1306,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpAMD64LoweredPanicBoundsCR:
|
case ssa.OpAMD64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - x86.REG_AX)
|
yVal = int(v.Args[0].Reg() - x86.REG_AX)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -777,7 +777,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpARMLoweredPanicBoundsCR:
|
case ssa.OpARMLoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - arm.REG_R0)
|
yVal = int(v.Args[0].Reg() - arm.REG_R0)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -1319,7 +1319,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpARM64LoweredPanicBoundsCR:
|
case ssa.OpARM64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - arm64.REG_R0)
|
yVal = int(v.Args[0].Reg() - arm64.REG_R0)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -811,7 +811,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpLOONG64LoweredPanicBoundsCR:
|
case ssa.OpLOONG64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - loong64.REG_R4)
|
yVal = int(v.Args[0].Reg() - loong64.REG_R4)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -551,7 +551,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpMIPSLoweredPanicBoundsCR:
|
case ssa.OpMIPSLoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - mips.REG_R1)
|
yVal = int(v.Args[0].Reg() - mips.REG_R1)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -542,7 +542,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpMIPS64LoweredPanicBoundsCR:
|
case ssa.OpMIPS64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - mips.REG_R1)
|
yVal = int(v.Args[0].Reg() - mips.REG_R1)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -1947,7 +1947,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpPPC64LoweredPanicBoundsCR:
|
case ssa.OpPPC64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - ppc64.REG_R3)
|
yVal = int(v.Args[0].Reg() - ppc64.REG_R3)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -544,7 +544,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpRISCV64LoweredPanicBoundsCR:
|
case ssa.OpRISCV64LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - riscv.REG_X5)
|
yVal = int(v.Args[0].Reg() - riscv.REG_X5)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -608,7 +608,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.OpS390XLoweredPanicBoundsCR:
|
case ssa.OpS390XLoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - s390x.REG_R0)
|
yVal = int(v.Args[0].Reg() - s390x.REG_R0)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
|
@ -804,7 +804,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
||||||
}
|
}
|
||||||
case ssa.Op386LoweredPanicBoundsCR:
|
case ssa.Op386LoweredPanicBoundsCR:
|
||||||
yIsReg = true
|
yIsReg = true
|
||||||
yVal := int(v.Args[0].Reg() - x86.REG_AX)
|
yVal = int(v.Args[0].Reg() - x86.REG_AX)
|
||||||
c := v.Aux.(ssa.PanicBoundsC).C
|
c := v.Aux.(ssa.PanicBoundsC).C
|
||||||
if c >= 0 && c <= abi.BoundsMaxConst {
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
||||||
xVal = int(c)
|
xVal = int(c)
|
||||||
|
|
33
test/fixedbugs/issue75327.go
Normal file
33
test/fixedbugs/issue75327.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// run
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
defer func() {
|
||||||
|
err := recover()
|
||||||
|
txt := fmt.Sprintf("%s", err)
|
||||||
|
if !strings.HasSuffix(txt, "with length 1") {
|
||||||
|
panic("bad error: " + txt)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
foo([]uint64{0})
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func foo(haystack []uint64) {
|
||||||
|
for n := range len(haystack) {
|
||||||
|
_ = n
|
||||||
|
_ = haystack[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
xxx := haystack[0:len(haystack)]
|
||||||
|
sink(xxx)
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func sink([]uint64) {}
|
Loading…
Add table
Add a link
Reference in a new issue