Skip to content

Commit 606019c

Browse files
committed
cmd/compile: trim function name prefix from escape diagnostics
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]>
1 parent 4ae25ff commit 606019c

23 files changed

+377
-377
lines changed

src/cmd/compile/internal/gc/esc.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func moveToHeap(n *Node) {
392392
n.Name.Param.Heapaddr = heapaddr
393393
n.Esc = EscHeap
394394
if Debug['m'] != 0 {
395-
fmt.Printf("%v: moved to heap: %v\n", n.Line(), n)
395+
Warnl(n.Pos, "moved to heap: %v", n)
396396
}
397397
}
398398

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

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

449449
if fn.Func.Pragma&UintptrEscapes != 0 {
450450
if f.Type.Etype == TUINTPTR {
451451
if Debug['m'] != 0 {
452-
Warnl(fn.Pos, "%v marking %v as escaping uintptr", funcSym(fn), name())
452+
Warnl(f.Pos, "marking %v as escaping uintptr", name())
453453
}
454454
return uintptrEscapesTag
455455
}
456456
if f.IsDDD() && f.Type.Elem().Etype == TUINTPTR {
457457
// final argument is ...uintptr.
458458
if Debug['m'] != 0 {
459-
Warnl(fn.Pos, "%v marking %v as escaping ...uintptr", funcSym(fn), name())
459+
Warnl(f.Pos, "marking %v as escaping ...uintptr", name())
460460
}
461461
return uintptrEscapesTag
462462
}
@@ -477,17 +477,17 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
477477

478478
if Debug['m'] != 0 && !loc.escapes {
479479
if esc == EscNone {
480-
Warnl(n.Pos, "%S %S does not escape", funcSym(fn), n)
480+
Warnl(f.Pos, "%v does not escape", name())
481481
} else if esc == EscHeap {
482-
Warnl(n.Pos, "leaking param: %S", n)
482+
Warnl(f.Pos, "leaking param: %v", name())
483483
} else {
484484
if esc&EscContentEscapes != 0 {
485-
Warnl(n.Pos, "leaking param content: %S", n)
485+
Warnl(f.Pos, "leaking param content: %v", name())
486486
}
487487
for i := 0; i < numEscReturns; i++ {
488488
if x := getEscReturn(esc, i); x >= 0 {
489-
res := n.Name.Curfn.Type.Results().Field(i).Sym
490-
Warnl(n.Pos, "leaking param: %S to result %v level=%d", n, res, x)
489+
res := fn.Type.Results().Field(i).Sym
490+
Warnl(f.Pos, "leaking param: %v to result %v level=%d", name(), res, x)
491491
}
492492
}
493493
}

src/cmd/compile/internal/gc/escape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ func (e *Escape) finish(fns []*Node) {
12891289
addrescapes(n)
12901290
} else {
12911291
if Debug['m'] != 0 && n.Op != ONAME && n.Op != OTYPESW && n.Op != ORANGE && n.Op != ODEFER {
1292-
Warnl(n.Pos, "%S %S does not escape", funcSym(loc.curfn), n)
1292+
Warnl(n.Pos, "%S does not escape", n)
12931293
}
12941294
n.Esc = EscNone
12951295
if loc.transient {

0 commit comments

Comments
 (0)