Skip to content

Commit

Permalink
cmd/compile: trim function name prefix from escape diagnostics
Browse files Browse the repository at this point in the history
This information is redundant with the position information already
provided. Also, no other -m diagnostics print out function name.

While here, report parameter leak diagnostics against the parameter
declaration position rather than the function, and use Warnl for
"moved to heap" messages.

Test cases updated programmatically by removing the first word from
every "no match for" error emitted by run.go:

go run run.go |& \
  sed -E -n 's/^(.*):(.*): no match for `([^ ]* (.*))` in:$/\1!\2!\3!\4/p' | \
  while IFS='!' read -r fn line before after; do
    before=$(echo "$before" | sed 's/[.[\*^$()+?{|]/\\&/g')
    after=$(echo "$after" | sed -E 's/(\&|\\)/\\&/g')
    fn=$(find . -name "${fn}" | head -1)
    sed -i -E -e "${line}s/\"${before}\"/\"${after}\"/" "${fn}"
  done

Passes toolstash-check.

Change-Id: I6e02486b1409e4a8dbb2b9b816d22095835426b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/195040
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
mdempsky committed Sep 16, 2019
1 parent 4ae25ff commit 606019c
Show file tree
Hide file tree
Showing 23 changed files with 377 additions and 377 deletions.
22 changes: 11 additions & 11 deletions src/cmd/compile/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func moveToHeap(n *Node) {
n.Name.Param.Heapaddr = heapaddr
n.Esc = EscHeap
if Debug['m'] != 0 {
fmt.Printf("%v: moved to heap: %v\n", n.Line(), n)
Warnl(n.Pos, "moved to heap: %v", n)
}
}

Expand Down Expand Up @@ -422,7 +422,7 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
// argument and pass those annotations along to importing code.
if f.Type.Etype == TUINTPTR {
if Debug['m'] != 0 {
Warnl(fn.Pos, "%v assuming %v is unsafe uintptr", funcSym(fn), name())
Warnl(f.Pos, "assuming %v is unsafe uintptr", name())
}
return unsafeUintptrTag
}
Expand All @@ -435,28 +435,28 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
// //go:noescape is given before the declaration.
if fn.Noescape() {
if Debug['m'] != 0 && f.Sym != nil {
Warnl(fn.Pos, "%S %v does not escape", funcSym(fn), name())
Warnl(f.Pos, "%v does not escape", name())
}
return mktag(EscNone)
}

if Debug['m'] != 0 && f.Sym != nil {
Warnl(fn.Pos, "leaking param: %v", name())
Warnl(f.Pos, "leaking param: %v", name())
}
return mktag(EscHeap)
}

if fn.Func.Pragma&UintptrEscapes != 0 {
if f.Type.Etype == TUINTPTR {
if Debug['m'] != 0 {
Warnl(fn.Pos, "%v marking %v as escaping uintptr", funcSym(fn), name())
Warnl(f.Pos, "marking %v as escaping uintptr", name())
}
return uintptrEscapesTag
}
if f.IsDDD() && f.Type.Elem().Etype == TUINTPTR {
// final argument is ...uintptr.
if Debug['m'] != 0 {
Warnl(fn.Pos, "%v marking %v as escaping ...uintptr", funcSym(fn), name())
Warnl(f.Pos, "marking %v as escaping ...uintptr", name())
}
return uintptrEscapesTag
}
Expand All @@ -477,17 +477,17 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {

if Debug['m'] != 0 && !loc.escapes {
if esc == EscNone {
Warnl(n.Pos, "%S %S does not escape", funcSym(fn), n)
Warnl(f.Pos, "%v does not escape", name())
} else if esc == EscHeap {
Warnl(n.Pos, "leaking param: %S", n)
Warnl(f.Pos, "leaking param: %v", name())
} else {
if esc&EscContentEscapes != 0 {
Warnl(n.Pos, "leaking param content: %S", n)
Warnl(f.Pos, "leaking param content: %v", name())
}
for i := 0; i < numEscReturns; i++ {
if x := getEscReturn(esc, i); x >= 0 {
res := n.Name.Curfn.Type.Results().Field(i).Sym
Warnl(n.Pos, "leaking param: %S to result %v level=%d", n, res, x)
res := fn.Type.Results().Field(i).Sym
Warnl(f.Pos, "leaking param: %v to result %v level=%d", name(), res, x)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ func (e *Escape) finish(fns []*Node) {
addrescapes(n)
} else {
if Debug['m'] != 0 && n.Op != ONAME && n.Op != OTYPESW && n.Op != ORANGE && n.Op != ODEFER {
Warnl(n.Pos, "%S %S does not escape", funcSym(loc.curfn), n)
Warnl(n.Pos, "%S does not escape", n)
}
n.Esc = EscNone
if loc.transient {
Expand Down
Loading

0 comments on commit 606019c

Please sign in to comment.