if max != nil {
k = s.extendIndex(s.expr(max), panicslice)
}
- p, l, c := s.slice(n.Left.Type, v, i, j, k)
+ p, l, c := s.slice(n.Left.Type, v, i, j, k, n.Bounded())
return s.newValue3(ssa.OpSliceMake, n.Type, p, l, c)
case OSLICESTR:
if high != nil {
j = s.extendIndex(s.expr(high), panicslice)
}
- p, l, _ := s.slice(n.Left.Type, v, i, j, nil)
+ p, l, _ := s.slice(n.Left.Type, v, i, j, nil, n.Bounded())
return s.newValue2(ssa.OpStringMake, n.Type, p, l)
case OCALLFUNC:
// slice computes the slice v[i:j:k] and returns ptr, len, and cap of result.
// i,j,k may be nil, in which case they are set to their default value.
// t is a slice, ptr to array, or string type.
-func (s *state) slice(t *types.Type, v, i, j, k *ssa.Value) (p, l, c *ssa.Value) {
+func (s *state) slice(t *types.Type, v, i, j, k *ssa.Value, bounded bool) (p, l, c *ssa.Value) {
var elemtype *types.Type
var ptrtype *types.Type
var ptr *ssa.Value
k = cap
}
- // Panic if slice indices are not in bounds.
- s.sliceBoundsCheck(i, j)
- if j != k {
- s.sliceBoundsCheck(j, k)
- }
- if k != cap {
- s.sliceBoundsCheck(k, cap)
+ if !bounded {
+ // Panic if slice indices are not in bounds.
+ s.sliceBoundsCheck(i, j)
+ if j != k {
+ s.sliceBoundsCheck(j, k)
+ }
+ if k != cap {
+ s.sliceBoundsCheck(k, cap)
+ }
}
// Generate the following code assuming that indexes are in bounds.
// s = s[:n]
nt := nod(OSLICE, s, nil)
nt.SetSliceBounds(nil, nn, nil)
+ nt.SetBounded(true)
nodes.Append(nod(OAS, s, nt))
var ncopy *Node
// s = s[:n]
nt := nod(OSLICE, s, nil)
nt.SetSliceBounds(nil, nn, nil)
+ nt.SetBounded(true)
nodes = append(nodes, nod(OAS, s, nt))
// lptr := &l1[0]
nx = nod(OSLICE, ns, nil) // ...s[:n+argc]
nx.SetSliceBounds(nil, nod(OADD, nn, na), nil)
+ nx.SetBounded(true)
l = append(l, nod(OAS, ns, nx)) // s = s[:n+argc]
ls = n.List.Slice()[1:]