transform: handle returned pointer alloc aliases

Follow returned pointer aliases when deciding whether runtime.alloc calls can
be lowered to stack allocations. A returned parameter is not the same as
nocapture: it still flows back to the caller and must be checked as an alias
of the original allocation.

Keep the analysis conservative for recursive returned-parameter chains and
unknown operands. The existing golden test now shows that the non-escaping
returned pointer cases no longer require heap allocation.
This commit is contained in:
Jake Bailey
2026-06-12 11:22:07 -07:00
committed by Ron Evans
parent 335b085fd2
commit a683881eb7
3 changed files with 71 additions and 9 deletions
-2
View File
@@ -1,4 +1,3 @@
testdata/allocs2.go:12.1,12.9 1 0
testdata/allocs2.go:21.1,21.22 1 0
testdata/allocs2.go:24.1,24.43 1 0
testdata/allocs2.go:26.1,26.25 1 0
@@ -8,7 +7,6 @@ testdata/allocs2.go:44.1,44.23 1 0
testdata/allocs2.go:46.1,46.22 1 0
testdata/allocs2.go:49.1,49.9 1 0
testdata/allocs2.go:50.1,50.9 1 0
testdata/allocs2.go:98.1,98.23 1 0
testdata/allocs2.go:107.1,107.21 1 0
testdata/allocs2.go:114.1,114.23 1 0
testdata/allocs2.go:128.1,128.23 1 0
+1 -3
View File
@@ -1,4 +1,3 @@
testdata/allocs2.go:12:2: object allocated on the heap: escapes at line 13
testdata/allocs2.go:21:12: object allocated on the heap: escapes at line 22
testdata/allocs2.go:24:15: object allocated on the heap: size is not constant
testdata/allocs2.go:26:12: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
@@ -8,7 +7,6 @@ testdata/allocs2.go:44:22: object allocated on the heap: escapes at line 44
testdata/allocs2.go:46:13: object allocated on the heap: escapes at line 47
testdata/allocs2.go:49:2: object allocated on the heap: escapes at line 51
testdata/allocs2.go:50:2: object allocated on the heap: escapes at line 51
testdata/allocs2.go:98:2: object allocated on the heap: escapes at line 100
testdata/allocs2.go:107:11: object allocated on the heap: escapes at line 108
testdata/allocs2.go:114:2: object allocated on the heap: escapes at line 116
testdata/allocs2.go:114:2: object allocated on the heap: escapes at line 117
testdata/allocs2.go:128:2: object allocated on the heap: escapes at line 130