import "unsafe"
func f(x **byte, y *byte) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f1(x *[]byte, y []byte) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f2(x *interface{}, y interface{}) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f2a(x *interface{}, y *interface{}) {
- *x = *y // ERROR "write barrier"
+ *x = *y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f3(x *string, y string) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
func t1(i interface{}) **int {
// From issue 14306, make sure we have write barriers in a type switch
// where the assigned variable escapes.
- switch x := i.(type) { // ERROR "write barrier"
- case *int:
+ switch x := i.(type) {
+ case *int: // ERROR "write barrier"
return &x
}
- switch y := i.(type) { // no write barrier here
- case **int:
+ switch y := i.(type) {
+ case **int: // no write barrier here
return y
}
return nil
}
var z21 int
-func f21(x *int) {
- // Global -> heap pointer updates must have write barriers.
- x21 = x // ERROR "write barrier"
- y21.x = x // ERROR "write barrier"
- x21 = &z21 // ERROR "write barrier"
- y21.x = &z21 // ERROR "write barrier"
+// f21x: Global -> heap pointer updates must have write barriers.
+func f21a(x *int) {
+ x21 = x // ERROR "write barrier"
+ y21.x = x // ERROR "write barrier"
+}
+
+func f21b(x *int) {
+ x21 = &z21 // ERROR "write barrier"
+ y21.x = &z21 // ERROR "write barrier"
+}
+
+func f21c(x *int) {
y21 = struct{ x *int }{x} // ERROR "write barrier"
}
*p = x // no barrier
return
}
+
+type T23 struct {
+ p *int
+ a int
+}
+
+var t23 T23
+var i23 int
+
+// f23x: zeroing global needs write barrier for the hybrid barrier.
+func f23a() {
+ t23 = T23{} // ERROR "write barrier"
+}
+
+func f23b() {
+ // also test partial assignments
+ t23 = T23{a: 1} // ERROR "write barrier"
+}
+
+func f23c() {
+ t23 = T23{} // no barrier (dead store)
+ // also test partial assignments
+ t23 = T23{p: &i23} // ERROR "write barrier"
+}
+
+var g int
+
+func f24() **int {
+ p := new(*int)
+ *p = &g // no write barrier here
+ return p
+}
+func f25() []string {
+ return []string{"abc", "def", "ghi"} // no write barrier here
+}
+
+type T26 struct {
+ a, b, c int
+ d, e, f *int
+}
+
+var g26 int
+
+func f26(p *int) *T26 { // see issue 29573
+ return &T26{
+ a: 5,
+ b: 6,
+ c: 7,
+ d: &g26, // no write barrier: global ptr
+ e: nil, // no write barrier: nil ptr
+ f: p, // ERROR "write barrier"
+ }
+}
+
+func f27(p *int) []interface{} {
+ return []interface{}{
+ nil, // no write barrier: zeroed memory, nil ptr
+ (*T26)(nil), // no write barrier: zeroed memory, type ptr & nil ptr
+ &g26, // no write barrier: zeroed memory, type ptr & global ptr
+ 7, // no write barrier: zeroed memory, type ptr & global ptr
+ p, // ERROR "write barrier"
+ }
+}
+
+var g28 [256]uint64
+
+func f28() []interface{} {
+ return []interface{}{
+ false, // no write barrier
+ true, // no write barrier
+ 0, // no write barrier
+ 1, // no write barrier
+ uint8(127), // no write barrier
+ int8(-4), // no write barrier
+ &g28[5], // no write barrier
+ }
+}