]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix bounds check report
authorKeith Randall <khr@golang.org>
Tue, 9 Sep 2025 05:04:40 +0000 (22:04 -0700)
committerKeith Randall <khr@golang.org>
Tue, 9 Sep 2025 14:37:40 +0000 (07:37 -0700)
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>

src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/arm/ssa.go
src/cmd/compile/internal/arm64/ssa.go
src/cmd/compile/internal/loong64/ssa.go
src/cmd/compile/internal/mips/ssa.go
src/cmd/compile/internal/mips64/ssa.go
src/cmd/compile/internal/ppc64/ssa.go
src/cmd/compile/internal/riscv64/ssa.go
src/cmd/compile/internal/s390x/ssa.go
src/cmd/compile/internal/x86/ssa.go
test/fixedbugs/issue75327.go [new file with mode: 0644]

index 8c8c7d90274dcb67755f1e4bdf391e663114e797..6331501dc92fdb35e68e346c3fa9312274b9c4b0 100644 (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)
index 91ef31c21521eeddb029bdd9ad3e1d1f59f08b7b..a3bfb491b8b25f8df8e745eb5dce8e9ee72feadd 100644 (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)
index 83293db9b92363d54824c56ce5d288e5ca4fea39..402ec493c268b0f95c85d41697fdcfabd11748de 100644 (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)
index 40fa10c6de7d3d509775642185d31e90e303d8f3..100ebf04567594a8b3dc6a153e91a148275931ac 100644 (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)
index 7390db29450f78da32cd3db9f10d074d8060e22a..c338fdc6b3e46b1d25b1562b1e5d6e65b89197a3 100644 (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)
index 37e2274ae8103953f103050743d2c93541491568..92788be00c2c3da5893c186b781063c1aa3b6305 100644 (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)
index 1086a9ccbf22dcdc5734511027df36791959c854..ace3024480e25371835edfba0faf259b7db61df9 100644 (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)
index 3d2f65a75e621245fb29686d02a76e4a18968ee5..88733b0d644a4b1de5f496eb96f20bdaadc43034 100644 (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)
index 86efde4fa09b878e6c3b6861b53a59e54d02f317..de00f1ef8ce9eea72f9d9d2b62d8b65c5e086dd6 100644 (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)
index 3347b38b284f369e7814db534ef25e718f88950c..d0aad08849635137fe22963f0b6afce919396ef6 100644 (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)
diff --git a/test/fixedbugs/issue75327.go b/test/fixedbugs/issue75327.go
new file mode 100644 (file)
index 0000000..9ca7c24
--- /dev/null
@@ -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) {}