From 98f5152368b4afd31eac1df2b3c172052d9b062a Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sun, 7 Aug 2022 01:55:52 +0700 Subject: [PATCH] cmd/compile: remove index out of bounds check in walkIndex Since when any user errors about out-of-bounds constants should have been already reported by types2. Change-Id: I81b6bfec53201bbf546c48157fc8154cdb3c6e45 Reviewed-on: https://go-review.googlesource.com/c/go/+/421876 Run-TryBot: Cuong Manh Le Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: David Chase --- src/cmd/compile/internal/walk/expr.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index 83fcea38d5..dfa82e7ec0 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -727,23 +727,11 @@ func walkIndex(n *ir.IndexExpr, init *ir.Nodes) ir.Node { if base.Flag.LowerM != 0 && n.Bounded() && !ir.IsConst(n.Index, constant.Int) { base.Warn("index bounds check elided") } - if ir.IsSmallIntConst(n.Index) && !n.Bounded() { - base.Errorf("index out of bounds") - } } else if ir.IsConst(n.X, constant.String) { n.SetBounded(bounded(r, int64(len(ir.StringVal(n.X))))) if base.Flag.LowerM != 0 && n.Bounded() && !ir.IsConst(n.Index, constant.Int) { base.Warn("index bounds check elided") } - if ir.IsSmallIntConst(n.Index) && !n.Bounded() { - base.Errorf("index out of bounds") - } - } - - if ir.IsConst(n.Index, constant.Int) { - if v := n.Index.Val(); constant.Sign(v) < 0 || ir.ConstOverflow(v, types.Types[types.TINT]) { - base.Errorf("index out of bounds") - } } return n } -- 2.48.1