transform: add -print-allocs-cover and restore -print-allocs reason output

PR #5220 changed -print-allocs output to the go coverage tool format, which
replaced the original human-readable explanation of why each object had to be
heap allocated. That explanation is useful on its own, so this restores it as
the default behavior of -print-allocs and moves the coverage format behind a
-print-allocs-cover flag.

Signed-off-by: Piotr Bocheński <piotr@bochen.ski>
This commit is contained in:
Piotr Bocheński
2026-06-11 21:33:05 +02:00
committed by Ron Evans
parent c33113ab5f
commit 4465360f3d
9 changed files with 130 additions and 91 deletions
+10 -10
View File
@@ -10,7 +10,7 @@ func main() {
derefInt(&n1)
// This should eventually be modified to not escape.
n2 := 6 // OUT: allocs2.go:52.1,52.42 1 0
n2 := 6
returnIntPtr(&n2)
s1 := make([]int, 3)
@@ -20,22 +20,22 @@ func main() {
readIntSlice(s2[:])
// This should also be modified to not escape.
s3 := make([]int, 3) // OUT: allocs2.go:51.1,51.42 1 0
s3 := make([]int, 3)
returnIntSlice(s3)
useSlice(make([]int, getUnknownNumber())) // OUT: allocs2.go:48.1,48.55 1 0
useSlice(make([]int, getUnknownNumber()))
s4 := make([]byte, 300) // OUT: allocs2.go:46.1,46.56 1 0
s4 := make([]byte, 300)
readByteSlice(s4)
s5 := make([]int, 4) // OUT: allocs2.go:38.1,38.56 1 0
s5 := make([]int, 4)
_ = append(s5, 5)
s6 := make([]int, 3)
s7 := []int{1, 2, 3}
copySlice(s6, s7)
c1 := getComplex128() // OUT: allocs2.go:31.1,31.55 1 0
c1 := getComplex128()
useInterface(c1)
n3 := 5
@@ -43,13 +43,13 @@ func main() {
return n3
}()
callVariadic(3, 5, 8) // OUT: allocs2.go:28.1,28.58 1 0
callVariadic(3, 5, 8)
s8 := []int{3, 5, 8} // OUT: allocs2.go:26.1,26.76 1 0
s8 := []int{3, 5, 8}
callVariadic(s8...)
n4 := 3 // OUT: allocs2.go:23.1,23.55 1 0
n5 := 7 // OUT: allocs2.go:13.1,13.42 1 0
n4 := 3
n5 := 7
func() {
n4 = n5
}()
+10
View File
@@ -0,0 +1,10 @@
testdata/allocs2.go:13.1,13.9 1 0
testdata/allocs2.go:23.1,23.22 1 0
testdata/allocs2.go:26.1,26.43 1 0
testdata/allocs2.go:28.1,28.25 1 0
testdata/allocs2.go:31.1,31.22 1 0
testdata/allocs2.go:38.1,38.23 1 0
testdata/allocs2.go:46.1,46.23 1 0
testdata/allocs2.go:48.1,48.22 1 0
testdata/allocs2.go:51.1,51.9 1 0
testdata/allocs2.go:52.1,52.9 1 0
+10
View File
@@ -0,0 +1,10 @@
testdata/allocs2.go:13:2: object allocated on the heap: escapes at line 14
testdata/allocs2.go:23:12: object allocated on the heap: escapes at line 24
testdata/allocs2.go:26:15: object allocated on the heap: size is not constant
testdata/allocs2.go:28:12: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
testdata/allocs2.go:31:12: object allocated on the heap: escapes at line 32
testdata/allocs2.go:38:21: object allocated on the heap: escapes at line 39
testdata/allocs2.go:46:22: object allocated on the heap: escapes at line 46
testdata/allocs2.go:48:13: object allocated on the heap: escapes at line 49
testdata/allocs2.go:51:2: object allocated on the heap: escapes at line 53
testdata/allocs2.go:52:2: object allocated on the heap: escapes at line 53