]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: catch and report nowritebarrier violations later
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 18:40:06 +0000 (11:40 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 16:31:20 +0000 (16:31 +0000)
Prior to this CL, the SSA backend reported violations
of the //go:nowritebarrier annotation immediately.
This necessitated emitting errors during SSA compilation,
which is not compatible with a concurrent backend.

Instead, check for such violations later.
We already save the data required to do a late check
for violations of the //go:nowritebarrierrec annotation.
Use the same data, and check //go:nowritebarrier at the same time.

One downside to doing this is that now only a single
violation will be reported per function.
Given that this is for the runtime only,
and violations are rare, this seems an acceptable cost.

While we are here, remove several 'nerrors != 0' checks
that are rendered pointless.

Updates #15756
Fixes #19250 (as much as it ever can be)

Change-Id: Ia44c4ad5b6fd6f804d9f88d9571cec8d23665cb3
Reviewed-on: https://go-review.googlesource.com/38973
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssa/writebarrier.go

index a514aa606a7f83ec241810aac9315848b2fc6711..b66231ab88272011ad3430255ba3ee401f8d3933 100644 (file)
@@ -1223,6 +1223,9 @@ func checknowritebarrierrec() {
        visitBottomUp(xtop, func(list []*Node, recursive bool) {
                // Functions with write barriers have depth 0.
                for _, n := range list {
+                       if n.Func.WBPos.IsKnown() && n.Func.Pragma&Nowritebarrier != 0 {
+                               yyerrorl(n.Func.WBPos, "write barrier prohibited")
+                       }
                        if n.Func.WBPos.IsKnown() && n.Func.Pragma&Yeswritebarrierrec == 0 {
                                c.best[n] = nowritebarrierrecCall{target: nil, depth: 0, lineno: n.Func.WBPos}
                        }
index 02cabc4a0258a2307847d48c4ac51af7ba379a0a..fdebae763a1bc09b595bcbc9b56fc8a1694b6385 100644 (file)
@@ -269,19 +269,12 @@ func compile(fn *Node) {
        if instrumenting {
                instrument(fn)
        }
-       if nerrors != 0 {
-               return
-       }
 
        // From this point, there should be no uses of Curfn. Enforce that.
        Curfn = nil
 
        // Build an SSA backend function.
        ssafn := buildssa(fn)
-       if nerrors != 0 {
-               return
-       }
-
        pp := newProgs(fn)
        genssa(ssafn, pp)
        fieldtrack(pp.Text.From.Sym, fn.Func.FieldTrack)
index cbd340974b5aef6612544d0f2ffab8891fe32963..794b8017f1f576f19fed07b17b54f3cc4076834a 100644 (file)
@@ -122,9 +122,6 @@ func buildssa(fn *Node) *ssa.Func {
        if fn.Func.Pragma&Nosplit != 0 {
                s.f.NoSplit = true
        }
-       if fn.Func.Pragma&Nowritebarrier != 0 {
-               s.f.NoWB = true
-       }
        defer func() {
                if s.f.WBPos.IsKnown() {
                        fn.Func.WBPos = s.f.WBPos
@@ -197,10 +194,6 @@ func buildssa(fn *Node) *ssa.Func {
                s.popLine()
        }
 
-       if nerrors > 0 {
-               return nil
-       }
-
        s.insertPhis()
 
        // Don't carry reference this around longer than necessary
@@ -208,10 +201,6 @@ func buildssa(fn *Node) *ssa.Func {
 
        // Main call to ssa package to compile function
        ssa.Compile(s.f)
-       if nerrors > 0 {
-               return nil
-       }
-
        return s.f
 }
 
@@ -4884,11 +4873,6 @@ func (e *ssafn) Fatalf(pos src.XPos, msg string, args ...interface{}) {
        Fatalf(msg, args...)
 }
 
-// Error reports a compiler error but keep going.
-func (e *ssafn) Error(pos src.XPos, msg string, args ...interface{}) {
-       yyerrorl(pos, msg, args...)
-}
-
 // Warnl reports a "warning", which is usually flag-triggered
 // logging output for the benefit of tests.
 func (e *ssafn) Warnl(pos src.XPos, fmt_ string, args ...interface{}) {
index 912fb16d8b579bac9a1d1cd0ee16780b8331989a..96a4c2b8ae7e06d6d4a40a86b21b1f1de4687729 100644 (file)
@@ -80,9 +80,6 @@ type Logger interface {
        // Fatal reports a compiler error and exits.
        Fatalf(pos src.XPos, msg string, args ...interface{})
 
-       // Error reports a compiler error but keep going.
-       Error(pos src.XPos, msg string, args ...interface{})
-
        // Warnl writes compiler messages in the form expected by "errorcheck" tests
        Warnl(pos src.XPos, fmt_ string, args ...interface{})
 
index c26df1b96457ac23e824104316e31f1805899295..f7a80a8c00bfa2f563bbdd6a892365af361a1999 100644 (file)
@@ -124,7 +124,6 @@ func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, arg
 func (d DummyFrontend) Log() bool                            { return true }
 
 func (d DummyFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
-func (d DummyFrontend) Error(_ src.XPos, msg string, args ...interface{})  { d.t.Errorf(msg, args...) }
 func (d DummyFrontend) Warnl(_ src.XPos, msg string, args ...interface{})  { d.t.Logf(msg, args...) }
 func (d DummyFrontend) Debug_checknil() bool                               { return false }
 func (d DummyFrontend) Debug_wb() bool                                     { return false }
index 17860957cff5dc42c2894528c075cc5c2851e85b..5093d0e7fc0da3e51cb5228a0c944eca58fc9324 100644 (file)
@@ -37,7 +37,6 @@ type Func struct {
        scheduled bool // Values in Blocks are in final order
        NoSplit   bool // true if function is marked as nosplit.  Used by schedule check pass.
 
-       NoWB  bool     // write barrier is not allowed
        WBPos src.XPos // line number of first write barrier
 
        // when register allocation is done, maps value ids to locations
index 35be9a09d7d18aa0115d94f78c4a4b7744fa0bad..1b6e51c674e630e0bec3556513917d628d1d9e16 100644 (file)
@@ -208,9 +208,6 @@ func writebarrier(f *Func) {
                                memElse.Aux = w.Aux
                        }
 
-                       if f.NoWB {
-                               f.fe.Error(pos, "write barrier prohibited")
-                       }
                        if !f.WBPos.IsKnown() {
                                f.WBPos = pos
                        }