Commit 58e2edaf authored by Austin Clements's avatar Austin Clements

cmd/compile: lower slice clears to memclrHasPointers

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/31450Reviewed-by: 's avatarKeith Randall <khr@golang.org>
Reviewed-by: 's avatarRick Hudson <rlh@golang.org>
parent ef3df189
...@@ -393,13 +393,11 @@ func memclrrange(n, v1, v2, a *Node) bool { ...@@ -393,13 +393,11 @@ func memclrrange(n, v1, v2, a *Node) bool {
return false return false
} }
// TODO: Use memclrHasPointers if there are pointers.
// Convert to // Convert to
// if len(a) != 0 { // if len(a) != 0 {
// hp = &a[0] // hp = &a[0]
// hn = len(a)*sizeof(elem(a)) // hn = len(a)*sizeof(elem(a))
// memclrNoHeapPointers(hp, hn) // memclr{NoHeap,Has}Pointers(hp, hn)
// i = len(a) - 1 // i = len(a) - 1
// } // }
n.Op = OIF n.Op = OIF
...@@ -425,8 +423,14 @@ func memclrrange(n, v1, v2, a *Node) bool { ...@@ -425,8 +423,14 @@ func memclrrange(n, v1, v2, a *Node) bool {
tmp = conv(tmp, Types[TUINTPTR]) tmp = conv(tmp, Types[TUINTPTR])
n.Nbody.Append(nod(OAS, hn, tmp)) n.Nbody.Append(nod(OAS, hn, tmp))
// memclrNoHeapPointers(hp, hn) var fn *Node
fn := mkcall("memclrNoHeapPointers", nil, nil, hp, hn) 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) n.Nbody.Append(fn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment