cmd/compile: enforce nowritebarrier in SSA compiler
Make sure we don't generate write barriers in runtime
code that is marked to forbid write barriers.
Implement the optimization that if we're writing a sliced
slice back to the location it came from, we don't need a
write barrier.
Fixes #14784
Change-Id: I04b6a3b2ac303c19817e932a36a3b006de103aaa
Reviewed-on: https://go-review.googlesource.com/20791
Reviewed-by: Austin Clements <austin@google.com>
diff --git a/test/writebarrier.go b/test/writebarrier.go
index e591eaa..7510728 100644
--- a/test/writebarrier.go
+++ b/test/writebarrier.go
@@ -168,3 +168,16 @@
x.f = f17 // no barrier
x.f = func(y *T17) { *y = *x } // ERROR "write barrier"
}
+
+type T18 struct {
+ a []int
+ s string
+}
+
+func f18(p *T18, x *[]int) {
+ p.a = p.a[:5] // no barrier
+ p.a = p.a[3:5] // no barrier
+ p.a = p.a[1:2:3] // no barrier
+ p.s = p.s[8:9] // no barrier
+ *x = (*x)[3:5] // no barrier
+}