diff options
author | Russ Cox <rsc@golang.org> | 2015-04-17 00:34:18 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2015-04-24 14:39:49 +0000 |
commit | 9406f68e6afd02fd588e8ca05ebb729a4f4b8d0d (patch) | |
tree | 7a6faf84692f7270855e513eef0dcfb6e0be907b /test/writebarrier.go | |
parent | 80f575b78fceeba3ab5ec5a5f08b26725734b341 (diff) | |
download | go-9406f68e6afd02fd588e8ca05ebb729a4f4b8d0d.tar.gz go-9406f68e6afd02fd588e8ca05ebb729a4f4b8d0d.zip |
cmd/internal/gc: add and test write barrier debug output
We can expand the test cases as we discover problems.
This is some basic tests plus all the things I got wrong
in some recent work.
Change-Id: Id875fcfaf74eb087ae42b441fe47a34c5b8ccb39
Reviewed-on: https://go-review.googlesource.com/9158
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'test/writebarrier.go')
-rw-r--r-- | test/writebarrier.go | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/test/writebarrier.go b/test/writebarrier.go new file mode 100644 index 0000000000..1f25d91ea4 --- /dev/null +++ b/test/writebarrier.go @@ -0,0 +1,110 @@ +// errorcheck -0 -l -d=wb + +// Copyright 2015 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 where write barriers are and are not emitted. + +package p + +import "unsafe" + +func f(x **byte, y *byte) { + *x = y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f1(x *[]byte, y []byte) { + *x = y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f1a(x *[]byte, y *[]byte) { + *x = *y // ERROR "write barrier" + + z := *y // no barrier + *x = z // ERROR "write barrier" +} + +func f2(x *interface{}, y interface{}) { + *x = y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f2a(x *interface{}, y *interface{}) { + *x = *y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f3(x *string, y string) { + *x = y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f3a(x *string, y *string) { + *x = *y // ERROR "write barrier" + + z := *y // no barrier + *x = z // ERROR "write barrier" +} + +func f4(x *[2]string, y [2]string) { + *x = y // ERROR "write barrier" + + z := y // no barrier + *x = z // ERROR "write barrier" +} + +func f4a(x *[2]string, y *[2]string) { + *x = *y // ERROR "write barrier" + + z := *y // no barrier + *x = z // ERROR "write barrier" +} + +type T struct { + X *int + Y int + M map[int]int +} + +func f5(t, u *T) { + t.X = &u.Y // ERROR "write barrier" +} + +func f6(t *T) { + t.M = map[int]int{1: 2} // ERROR "write barrier" +} + +func f7(x, y *int) []*int { + var z [3]*int + i := 0 + z[i] = x // ERROR "write barrier" + i++ + z[i] = y // ERROR "write barrier" + i++ + return z[:i] +} + +func f9(x *interface{}, v *byte) { + *x = v // ERROR "write barrier" +} + +func f10(x *byte, f func(interface{})) { + f(x) +} + +func f11(x *unsafe.Pointer, y unsafe.Pointer) { + *x = unsafe.Pointer(uintptr(y) + 1) // ERROR "write barrier" +} |