]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: mark memclrHasPointers calls as write barriers
authorAustin Clements <austin@google.com>
Wed, 5 Dec 2018 20:21:17 +0000 (15:21 -0500)
committerAustin Clements <austin@google.com>
Wed, 5 Dec 2018 21:54:52 +0000 (21:54 +0000)
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: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/range.go
src/cmd/compile/internal/gc/walk.go

index bf30d9388ec55f4385cf0fb1bff6c9b4f4e30760..cbe69a1ebc16fdff770fd4637bbc90dc1671bbce 100644 (file)
@@ -588,6 +588,7 @@ func arrayClear(n, v1, v2, a *Node) bool {
        var fn *Node
        if types.Haspointers(a.Type.Elem()) {
                // memclrHasPointers(hp, hn)
+               Curfn.Func.setWBPos(stmt.Pos)
                fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
        } else {
                // memclrNoHeapPointers(hp, hn)
index 528aacb213c4b4ef9e0dd7ea1a7671a0175e4869..b84bc26e04a720a7ef49a10d827a1bc304e923de 100644 (file)
@@ -2860,6 +2860,7 @@ func extendslice(n *Node, init *Nodes) *Node {
        hasPointers := types.Haspointers(elemtype)
        if hasPointers {
                clrname = "memclrHasPointers"
+               Curfn.Func.setWBPos(n.Pos)
        }
 
        var clr Nodes