mirror of https://github.com/golang/go.git
cmd/compile: omit write barrier when assigning global function
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>
This commit is contained in:
parent
4e75932cf7
commit
3e54ca9a46
|
|
@ -2140,6 +2140,12 @@ func needwritebarrier(l *Node, r *Node) bool {
|
||||||
return false
|
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.
|
// Otherwise, be conservative and use write barrier.
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,3 +158,13 @@ func t1(i interface{}) **int {
|
||||||
}
|
}
|
||||||
return nil
|
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"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue