aboutsummaryrefslogtreecommitdiff
path: root/test/notinheap3.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2018-12-05 15:23:26 -0500
committerAustin Clements <austin@google.com>2018-12-05 21:54:54 +0000
commit6454a09a97ff583bd81d59733777a000caf8b79a (patch)
treecc9a95229bd3da89f3db56b9ea8972b289721045 /test/notinheap3.go
parentc8ca793176cfae8a9fc501d6e37896304f483f2e (diff)
downloadgo-6454a09a97ff583bd81d59733777a000caf8b79a.tar.gz
go-6454a09a97ff583bd81d59733777a000caf8b79a.zip
cmd/compile: omit write barriers for slice clears of go:notinheap pointers
Currently, for i := range a { a[i] = nil } will compile to have write barriers even if a is a slice of pointers to go:notinheap types. This happens because the optimization that transforms this into a memclr only asks it a's element type has pointers, and not if it specifically has heap pointers. Fix this by changing arrayClear to use HasHeapPointer instead of types.Haspointers. We probably shouldn't have both of these functions, since a pointer to a notinheap type is effectively a uintptr, but that's not going to change in this CL. Change-Id: I284b85bdec6ae1e641f894e8f577989facdb0cf1 Reviewed-on: https://go-review.googlesource.com/c/152723 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'test/notinheap3.go')
-rw-r--r--test/notinheap3.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/notinheap3.go b/test/notinheap3.go
index d48c2a0cc9..5ace8d6793 100644
--- a/test/notinheap3.go
+++ b/test/notinheap3.go
@@ -58,3 +58,19 @@ func h() {
_ = append(v1s, v1s...) // no barrier
_ = append(v2s, v2s...) // ERROR "write barrier"
}
+
+// Slice clearing
+
+var (
+ sliceIH []*ih
+ sliceNIH []*nih
+)
+
+func sliceClear() {
+ for i := range sliceIH {
+ sliceIH[i] = nil // ERROR "write barrier"
+ }
+ for i := range sliceNIH {
+ sliceNIH[i] = nil // no barrier
+ }
+}