]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: lower slice clears to memclrHasPointers
authorAustin Clements <austin@google.com>
Tue, 18 Oct 2016 14:01:56 +0000 (10:01 -0400)
committerAustin Clements <austin@google.com>
Fri, 28 Oct 2016 19:13:13 +0000 (19:13 +0000)
If a slice's backing store has pointers, we need to lower clears of
that slice to memclrHasPointers instead of memclrNoHeapPointers.

Updates #17503.

Change-Id: I20750e4bf57f7b8862f3d898bfb32d964b91d07b
Reviewed-on: https://go-review.googlesource.com/31450
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/cmd/compile/internal/gc/range.go

index 59dfba5b1ec8ebbbbdac99105bf05b712b9c850b..b59047428f6b893a1a6664c01d63ea23985d2ecf 100644 (file)
@@ -393,13 +393,11 @@ func memclrrange(n, v1, v2, a *Node) bool {
                return false
        }
 
-       // TODO: Use memclrHasPointers if there are pointers.
-
        // Convert to
        // if len(a) != 0 {
        //      hp = &a[0]
        //      hn = len(a)*sizeof(elem(a))
-       //      memclrNoHeapPointers(hp, hn)
+       //      memclr{NoHeap,Has}Pointers(hp, hn)
        //      i = len(a) - 1
        // }
        n.Op = OIF
@@ -425,8 +423,14 @@ func memclrrange(n, v1, v2, a *Node) bool {
        tmp = conv(tmp, Types[TUINTPTR])
        n.Nbody.Append(nod(OAS, hn, tmp))
 
-       // memclrNoHeapPointers(hp, hn)
-       fn := mkcall("memclrNoHeapPointers", nil, nil, hp, hn)
+       var fn *Node
+       if haspointers(a.Type.Elem()) {
+               // memclrHasPointers(hp, hn)
+               fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
+       } else {
+               // memclrNoHeapPointers(hp, hn)
+               fn = mkcall("memclrNoHeapPointers", nil, nil, hp, hn)
+       }
 
        n.Nbody.Append(fn)