]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: consistently use strlit to access constants string values
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 13 Sep 2019 18:29:19 +0000 (01:29 +0700)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 16 Sep 2019 11:41:20 +0000 (11:41 +0000)
Passes toolstash-check.

Change-Id: Ieaef20b7649787727b69469f93ffc942022bc079
Reviewed-on: https://go-review.googlesource.com/c/go/+/195198
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index e40c23b8efefb0200e11160b28bfe68b19e22994..510b1cd15dced89cac570aeb87388db520268f46 100644 (file)
@@ -612,7 +612,7 @@ func evconst(n *Node) {
                                var strs []string
                                i2 := i1
                                for i2 < len(s) && Isconst(s[i2], CTSTR) {
-                                       strs = append(strs, s[i2].Val().U.(string))
+                                       strs = append(strs, strlit(s[i2]))
                                        i2++
                                }
 
@@ -635,7 +635,7 @@ func evconst(n *Node) {
                switch nl.Type.Etype {
                case TSTRING:
                        if Isconst(nl, CTSTR) {
-                               setintconst(n, int64(len(nl.Val().U.(string))))
+                               setintconst(n, int64(len(strlit(nl))))
                        }
                case TARRAY:
                        if !hascallchan(nl) {
index a60b854b2c7dd8d7bafc8309612373c921440edb..6bbabb45ddd4f5a594d38f705d58cc226b8a0b3b 100644 (file)
@@ -762,7 +762,7 @@ func (p *noder) sum(x syntax.Expr) *Node {
        n := p.expr(x)
        if Isconst(n, CTSTR) && n.Sym == nil {
                nstr = n
-               chunks = append(chunks, nstr.Val().U.(string))
+               chunks = append(chunks, strlit(nstr))
        }
 
        for i := len(adds) - 1; i >= 0; i-- {
@@ -772,12 +772,12 @@ func (p *noder) sum(x syntax.Expr) *Node {
                if Isconst(r, CTSTR) && r.Sym == nil {
                        if nstr != nil {
                                // Collapse r into nstr instead of adding to n.
-                               chunks = append(chunks, r.Val().U.(string))
+                               chunks = append(chunks, strlit(r))
                                continue
                        }
 
                        nstr = r
-                       chunks = append(chunks, nstr.Val().U.(string))
+                       chunks = append(chunks, strlit(nstr))
                } else {
                        if len(chunks) > 1 {
                                nstr.SetVal(Val{U: strings.Join(chunks, "")})
index 0ea43f114e27f90eb2aed481cf75f642b971391f..ee04b69a680399d20dce63b7dc4d504f6575ddca 100644 (file)
@@ -1017,7 +1017,7 @@ func (o *Order) expr(n, lhs *Node) *Node {
                haslit := false
                for _, n1 := range n.List.Slice() {
                        hasbyte = hasbyte || n1.Op == OBYTES2STR
-                       haslit = haslit || n1.Op == OLITERAL && len(n1.Val().U.(string)) != 0
+                       haslit = haslit || n1.Op == OLITERAL && len(strlit(n1)) != 0
                }
 
                if haslit && hasbyte {
index ae8e79d854b5e6a0e5a3313f8fc209ec5f5b6f9e..ae16d41b1ccd24eb2f9f30698a1c31e606dafc57 100644 (file)
@@ -211,7 +211,7 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool {
 
        case OSTR2BYTES:
                if l.Class() == PEXTERN && r.Left.Op == OLITERAL {
-                       sval := r.Left.Val().U.(string)
+                       sval := strlit(r.Left)
                        slicebytes(l, sval, len(sval))
                        return true
                }
index 97d9b0f9129253191ce03d4fdf1d8ba1e436355e..7b0c7e5c4331aed0e20acb1b04d651c5267e46f7 100644 (file)
@@ -2336,7 +2336,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                                // Replace "abc"[1] with 'b'.
                                // Delayed until now because "abc"[1] is not an ideal constant.
                                // See test/fixedbugs/issue11370.go.
-                               return s.newValue0I(ssa.OpConst8, types.Types[TUINT8], int64(int8(n.Left.Val().U.(string)[n.Right.Int64()])))
+                               return s.newValue0I(ssa.OpConst8, types.Types[TUINT8], int64(int8(strlit(n.Left)[n.Right.Int64()])))
                        }
                        a := s.expr(n.Left)
                        i := s.expr(n.Right)
index e725c6f363442bc7503e5abbd661255022f06f88..050a74b1e60938c23f09d83ffda9ffeb0bba6d00 100644 (file)
@@ -1043,8 +1043,8 @@ func typecheck1(n *Node, top int) (res *Node) {
                                        yyerror("invalid %s index %v (index must be non-negative)", why, n.Right)
                                } else if t.IsArray() && x >= t.NumElem() {
                                        yyerror("invalid array index %v (out of bounds for %d-element array)", n.Right, t.NumElem())
-                               } else if Isconst(n.Left, CTSTR) && x >= int64(len(n.Left.Val().U.(string))) {
-                                       yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(n.Left.Val().U.(string)))
+                               } else if Isconst(n.Left, CTSTR) && x >= int64(len(strlit(n.Left))) {
+                                       yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(strlit(n.Left)))
                                } else if n.Right.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
                                        yyerror("invalid %s index %v (index too large)", why, n.Right)
                                }
@@ -2148,8 +2148,8 @@ func checksliceindex(l *Node, r *Node, tp *types.Type) bool {
                } else if tp != nil && tp.NumElem() >= 0 && r.Int64() > tp.NumElem() {
                        yyerror("invalid slice index %v (out of bounds for %d-element array)", r, tp.NumElem())
                        return false
-               } else if Isconst(l, CTSTR) && r.Int64() > int64(len(l.Val().U.(string))) {
-                       yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val().U.(string)))
+               } else if Isconst(l, CTSTR) && r.Int64() > int64(len(strlit(l))) {
+                       yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(strlit(l)))
                        return false
                } else if r.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
                        yyerror("invalid slice index %v (index too large)", r)
@@ -3409,7 +3409,7 @@ func stringtoruneslit(n *Node) *Node {
        }
 
        var l []*Node
-       s := n.Left.Val().U.(string)
+       s := strlit(n.Left)
        i := 0
        for _, r := range s {
                l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
index cb49e0f7ce2e8e4b8e638653a8f4eb04feb6a3b7..d2036b6e32fbf87a09328929e7d2407d6e9520ac 100644 (file)
@@ -1054,7 +1054,7 @@ opswitch:
                                yyerror("index out of bounds")
                        }
                } else if Isconst(n.Left, CTSTR) {
-                       n.SetBounded(bounded(r, int64(len(n.Left.Val().U.(string)))))
+                       n.SetBounded(bounded(r, int64(len(strlit(n.Left)))))
                        if Debug['m'] != 0 && n.Bounded() && !Isconst(n.Right, CTINT) {
                                Warn("index bounds check elided")
                        }
@@ -1389,7 +1389,7 @@ opswitch:
        case OSTR2BYTES:
                s := n.Left
                if Isconst(s, CTSTR) {
-                       sc := s.Val().U.(string)
+                       sc := strlit(s)
 
                        // Allocate a [n]byte of the right size.
                        t := types.NewArray(types.Types[TUINT8], int64(len(sc)))
@@ -1792,7 +1792,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
        for i := 0; i < len(s); {
                var strs []string
                for i < len(s) && Isconst(s[i], CTSTR) {
-                       strs = append(strs, s[i].Val().U.(string))
+                       strs = append(strs, strlit(s[i]))
                        i++
                }
                if len(strs) > 0 {
@@ -1861,7 +1861,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
                case TSTRING:
                        cs := ""
                        if Isconst(n, CTSTR) {
-                               cs = n.Val().U.(string)
+                               cs = strlit(n)
                        }
                        switch cs {
                        case " ":
@@ -2510,7 +2510,7 @@ func addstr(n *Node, init *Nodes) *Node {
                sz := int64(0)
                for _, n1 := range n.List.Slice() {
                        if n1.Op == OLITERAL {
-                               sz += int64(len(n1.Val().U.(string)))
+                               sz += int64(len(strlit(n1)))
                        }
                }
 
@@ -3350,7 +3350,7 @@ func walkcompareString(n *Node, init *Nodes) *Node {
                        // Length-only checks are ok, though.
                        maxRewriteLen = 0
                }
-               if s := cs.Val().U.(string); len(s) <= maxRewriteLen {
+               if s := strlit(cs); len(s) <= maxRewriteLen {
                        if len(s) > 0 {
                                ncs = safeexpr(ncs, init)
                        }