src/cmd/compile/internal/gc/sinit.go | 8 ++++++++ src/cmd/compile/internal/gc/walk.go | 15 +++++++++++---- test/sinit.go | 5 +++++ diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index e1a99d4ca0ee681297bb3c4d393b8b799529ddc4..0ced4ef3b0928bf3cd97fe98db2f5f4a24e2e5b6 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -302,6 +302,10 @@ } orig := r r = r.Name.Defn.Right + for r.Op == OCONVNOP { + r = r.Left + } + switch r.Op { case ONAME: if staticcopy(l, r, out) { @@ -394,6 +398,10 @@ } func staticassign(l *Node, r *Node, out **NodeList) bool { var n1 Node + + for r.Op == OCONVNOP { + r = r.Left + } switch r.Op { //dump("not static", r); diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 626b26fec7f3462676656a6eee7f47ca72ab3c52..d89d25efdd8c90f9effe6211ab95c016ff258763 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -2194,13 +2194,20 @@ if isstack(l) { return false } - // No write barrier for implicit or explicit zeroing. - if r == nil || iszero(r) { + // No write barrier for implicit zeroing. + if r == nil { return false } - // No write barrier for initialization to constant. - if r.Op == OLITERAL { + // Ignore no-op conversions when making decision. + // Ensures that xp = unsafe.Pointer(&x) is treated + // the same as xp = &x. + for r.Op == OCONVNOP { + r = r.Left + } + + // No write barrier for zeroing or initialization to constant. + if iszero(r) || r.Op == OLITERAL { return false } diff --git a/test/sinit.go b/test/sinit.go index df1a4cc930ca784b3ae166f71db16f9f03ab54a5..188a5301a2f35d41e949dea0b26deee61c834898 100644 --- a/test/sinit.go +++ b/test/sinit.go @@ -10,6 +10,8 @@ // This test is run by sinit_run.go. package p +import "unsafe" + // Should be no init func in the assembly. // All these initializations should be done at link time. @@ -284,3 +286,6 @@ M() } var _ Mer = (*T1)(nil) + +var Byte byte +var PtrByte unsafe.Pointer = unsafe.Pointer(&Byte)