diff options
author | Austin Clements <austin@google.com> | 2017-10-24 16:34:33 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2017-10-29 20:21:47 +0000 |
commit | 316e3036a7dda449ed9e64b3ab86ef686080a343 (patch) | |
tree | 1d2a5761c25d9837f998e386ca88c2e25fcba7a9 /test/notinheap3.go | |
parent | afbe646ab4480696d61462e9cab2ad048b5c1b6c (diff) | |
download | go-316e3036a7dda449ed9e64b3ab86ef686080a343.tar.gz go-316e3036a7dda449ed9e64b3ab86ef686080a343.zip |
cmd/compile: make HasHeapPointer recursive
Currently (*Type).HasHeapPointer only ignores pointers go:notinheap
types if the type itself is a pointer to a go:notinheap type. However,
if it's some other type that contains pointers where all of those
pointers are go:notinheap, it will conservatively return true. As a
result, we'll use write barriers where they aren't needed, for example
calling typedmemmove instead of just memmove on structs that contain
only go:notinheap pointers.
Fix this by making HasHeapPointer walk the whole type looking for
pointers that aren't marked go:notinheap.
Change-Id: Ib8c6abf6f7a20f34969d1d402c5498e0b990be59
Reviewed-on: https://go-review.googlesource.com/73412
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/notinheap3.go')
-rw-r--r-- | test/notinheap3.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/notinheap3.go b/test/notinheap3.go new file mode 100644 index 0000000000..e01c7a0a82 --- /dev/null +++ b/test/notinheap3.go @@ -0,0 +1,45 @@ +// errorcheck -+ -0 -l -d=wb + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test write barrier elimination for notinheap. + +package p + +type t1 struct { + x *nih + y [1024]byte // Prevent write decomposition +} + +type t2 struct { + x *ih + y [1024]byte +} + +//go:notinheap +type nih struct { + x uintptr +} + +type ih struct { // In-heap type + x uintptr +} + +var ( + v1 t1 + v2 t2 +) + +func f() { + // Test direct writes + v1.x = nil // no barrier + v2.x = nil // ERROR "write barrier" +} + +func g() { + // Test aggregate writes + v1 = t1{x: nil} // no barrier + v2 = t2{x: nil} // ERROR "write barrier" +} |