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:
Keith Randall 2025-09-08 22:04:40 -07:00
parent 6447ff409a
commit af03343f93
11 changed files with 43 additions and 10 deletions

View file

@ -1306,7 +1306,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpAMD64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -777,7 +777,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpARMLoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -1319,7 +1319,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpARM64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -811,7 +811,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpLOONG64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -551,7 +551,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpMIPSLoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -542,7 +542,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpMIPS64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -1947,7 +1947,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpPPC64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -544,7 +544,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpRISCV64LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -608,7 +608,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.OpS390XLoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View file

@ -804,7 +804,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
}
case ssa.Op386LoweredPanicBoundsCR:
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
if c >= 0 && c <= abi.BoundsMaxConst {
xVal = int(c)

View 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) {}