]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: omit write barrier when assigning global function
authorAustin Clements <austin@google.com>
Wed, 16 Mar 2016 22:22:58 +0000 (18:22 -0400)
committerAustin Clements <austin@google.com>
Wed, 16 Mar 2016 22:42:45 +0000 (22:42 +0000)
Currently we generate write barriers when the right side of an
assignment is a global function. This doesn't fall into the existing
case of storing an address of a global because we haven't lowered the
function to a pointer yet.

This write barrier is unnecessary, so eliminate it.

Fixes #13901.

Change-Id: Ibc10e00a8803db0fd75224b66ab94c3737842a79
Reviewed-on: https://go-review.googlesource.com/20772
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/walk.go
test/writebarrier.go

index b4c38ec12bacd9174f5eb3518e5291f3e446e176..69c8390fe0f931ad3f01506a62c0499b7dc5d26c 100644 (file)
@@ -2140,6 +2140,12 @@ func needwritebarrier(l *Node, r *Node) bool {
                return false
        }
 
+       // No write barrier for storing global function, which is live
+       // no matter what.
+       if r.Op == ONAME && r.Class == PFUNC {
+               return false
+       }
+
        // Otherwise, be conservative and use write barrier.
        return true
 }
index dcd20a02252e838c709843178db7f736b83d30b4..e591eaab32b642eaadafef8ac00b0f0d961ac5e3 100644 (file)
@@ -158,3 +158,13 @@ func t1(i interface{}) **int {
        }
        return nil
 }
+
+type T17 struct {
+       f func(*T17)
+}
+
+func f17(x *T17) {
+       // See golang.org/issue/13901
+       x.f = f17                      // no barrier
+       x.f = func(y *T17) { *y = *x } // ERROR "write barrier"
+}