diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-24 09:07:52 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-24 18:24:24 +0000 |
commit | df00abc61b415eb05d4df9fd2bf3fdda1aaaaba3 (patch) | |
tree | e14f08c8088d5a8dc1849031e79c8dc180e7d7f3 /src | |
parent | b55cc6687d8f805663e9e803ad5293d1b399ce37 (diff) | |
download | go-git-df00abc61b415eb05d4df9fd2bf3fdda1aaaaba3.tar.gz |
[dev.typeparams] cmd/compile: skip escape analysis diagnostics for wrappers
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/compile/internal/escape/escape.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go index 324d0da3fe..317bc98473 100644 --- a/src/cmd/compile/internal/escape/escape.go +++ b/src/cmd/compile/internal/escape/escape.go @@ -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()) } |