aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/compile/internal/escape/escape.go7
-rw-r--r--test/escape5.go11
2 files changed, 15 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go
index 58cad73c76..213ef7832d 100644
--- a/src/cmd/compile/internal/escape/escape.go
+++ b/src/cmd/compile/internal/escape/escape.go
@@ -1625,9 +1625,10 @@ func containsClosure(f, c *ir.Func) bool {
// leak records that parameter l leaks to sink.
func (l *location) leakTo(sink *location, derefs int) {
- // If sink is a result parameter and we can fit return bits
- // into the escape analysis tag, then record a return leak.
- if sink.isName(ir.PPARAMOUT) && sink.curfn == l.curfn {
+ // If sink is a result parameter that doesn't escape (#44614)
+ // and we can fit return bits into the escape analysis tag,
+ // then record as a result leak.
+ if !sink.escapes && sink.isName(ir.PPARAMOUT) && sink.curfn == l.curfn {
ri := sink.resultIndex - 1
if ri < numEscResults {
// Leak to result parameter.
diff --git a/test/escape5.go b/test/escape5.go
index 2ed2023cd2..82be2c38e7 100644
--- a/test/escape5.go
+++ b/test/escape5.go
@@ -269,3 +269,14 @@ func f28369(n int) int {
return 1 + f28369(n-1)
}
+
+// Issue 44614: parameters that flow to a heap-allocated result
+// parameter must be recorded as a heap-flow rather than a
+// result-flow.
+
+// N.B., must match "leaking param: p",
+// but *not* "leaking param: p to result r level=0".
+func f(p *int) (r *int) { // ERROR "leaking param: p$" "moved to heap: r"
+ sink4 = &r
+ return p
+}