Commit c8ca7931 authored by Austin Clements's avatar Austin Clements

cmd/compile: mark memclrHasPointers calls as write barriers

There are two places where the compiler generates memclrHasPointers
calls. These are effectively write barriers, but the compiler doesn't
currently record them as such in the function. As a result code like

  for i := range a {
    a[i] = nil
  }

inserts a write barrier for the assignment to a[i], but the compiler
doesn't report this. Hence, it's not reported in the -d=wb output, and
it's not checked against //go:nowritebarrier annotations.

Change-Id: I40299ebc9824f05cf516cba494d4c086b80ffb53
Reviewed-on: https://go-review.googlesource.com/c/152722
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 162de6b5
...@@ -588,6 +588,7 @@ func arrayClear(n, v1, v2, a *Node) bool { ...@@ -588,6 +588,7 @@ func arrayClear(n, v1, v2, a *Node) bool {
var fn *Node var fn *Node
if types.Haspointers(a.Type.Elem()) { if types.Haspointers(a.Type.Elem()) {
// memclrHasPointers(hp, hn) // memclrHasPointers(hp, hn)
Curfn.Func.setWBPos(stmt.Pos)
fn = mkcall("memclrHasPointers", nil, nil, hp, hn) fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
} else { } else {
// memclrNoHeapPointers(hp, hn) // memclrNoHeapPointers(hp, hn)
......
...@@ -2860,6 +2860,7 @@ func extendslice(n *Node, init *Nodes) *Node { ...@@ -2860,6 +2860,7 @@ func extendslice(n *Node, init *Nodes) *Node {
hasPointers := types.Haspointers(elemtype) hasPointers := types.Haspointers(elemtype)
if hasPointers { if hasPointers {
clrname = "memclrHasPointers" clrname = "memclrHasPointers"
Curfn.Func.setWBPos(n.Pos)
} }
var clr Nodes var clr Nodes
......
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