From: Cuong Manh Le Date: Sat, 6 Aug 2022 18:55:52 +0000 (+0700) Subject: cmd/compile: remove index out of bounds check in walkIndex X-Git-Tag: go1.20rc1~1775 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=98f5152368b4afd31eac1df2b3c172052d9b062a;p=gostls13.git 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 --- 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 }