]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: skip escape analysis diagnostics for wrappers
authorMatthew Dempsky <mdempsky@google.com>
Thu, 24 Jun 2021 16:07:52 +0000 (09:07 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 24 Jun 2021 18:24:24 +0000 (18:24 +0000)
This CL changes escape analysis to skip reporting diagnostics (at
least for parameter tagging) for generated wrappers.

We're inconsistent about when/where wrappers are generated, which made
errorcheck tests of escape analysis unnecessarily brittle to changes
in wrapper generation. This CL addresses this making errorcheck tests
only care about tagging of the actual functions themselves, not the
wrappers too.

Change-Id: Ia1a0b9dabee4d4162b05647f871db03b032c945a
Reviewed-on: https://go-review.googlesource.com/c/go/+/330689
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/escape/escape.go
test/uintptrescapes2.go

index 324d0da3fe5d56326355ba2b580174c23a813eef..317bc98473cd04b3db30c05233bc69336344f4da 100644 (file)
@@ -365,6 +365,11 @@ func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
                return fmt.Sprintf("arg#%d", narg)
        }
 
+       // Only report diagnostics for user code;
+       // not for wrappers generated around them.
+       // TODO(mdempsky): Generalize this.
+       diagnose := base.Flag.LowerM != 0 && !(fn.Wrapper() || fn.Dupok())
+
        if len(fn.Body) == 0 {
                // Assume that uintptr arguments must be held live across the call.
                // This is most important for syscall.Syscall.
@@ -375,7 +380,7 @@ func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
                fn.Pragma |= ir.UintptrKeepAlive
 
                if f.Type.IsUintptr() {
-                       if base.Flag.LowerM != 0 {
+                       if diagnose {
                                base.WarnfAt(f.Pos, "assuming %v is unsafe uintptr", name())
                        }
                        return ""
@@ -390,11 +395,11 @@ func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
                // External functions are assumed unsafe, unless
                // //go:noescape is given before the declaration.
                if fn.Pragma&ir.Noescape != 0 {
-                       if base.Flag.LowerM != 0 && f.Sym != nil {
+                       if diagnose && f.Sym != nil {
                                base.WarnfAt(f.Pos, "%v does not escape", name())
                        }
                } else {
-                       if base.Flag.LowerM != 0 && f.Sym != nil {
+                       if diagnose && f.Sym != nil {
                                base.WarnfAt(f.Pos, "leaking param: %v", name())
                        }
                        esc.AddHeap(0)
@@ -407,14 +412,14 @@ func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
                fn.Pragma |= ir.UintptrKeepAlive
 
                if f.Type.IsUintptr() {
-                       if base.Flag.LowerM != 0 {
+                       if diagnose {
                                base.WarnfAt(f.Pos, "marking %v as escaping uintptr", name())
                        }
                        return ""
                }
                if f.IsDDD() && f.Type.Elem().IsUintptr() {
                        // final argument is ...uintptr.
-                       if base.Flag.LowerM != 0 {
+                       if diagnose {
                                base.WarnfAt(f.Pos, "marking %v as escaping ...uintptr", name())
                        }
                        return ""
@@ -436,7 +441,7 @@ func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
        esc := loc.paramEsc
        esc.Optimize()
 
-       if base.Flag.LowerM != 0 && !loc.escapes {
+       if diagnose && !loc.escapes {
                if esc.Empty() {
                        base.WarnfAt(f.Pos, "%v does not escape", name())
                }
index 3ff1d940425863caae41c03e59a1a57d379e97e0..656286c0ff2bd72e7580bd7592a533d4a346d1df 100644 (file)
@@ -30,7 +30,7 @@ type T struct{}
 func (T) M1(a uintptr) {} // ERROR "escaping uintptr"
 
 //go:uintptrescapes
-func (T) M2(a ...uintptr) {} // ERROR "escaping ...uintptr" "leaking param: a"
+func (T) M2(a ...uintptr) {} // ERROR "escaping ...uintptr"
 
 func TestF1() {
        var t int                        // ERROR "moved to heap"