Skip to content

cmd/compile: recursive functions are escape analyzed context insensitively #62501

Open
@mdempsky

Description

@mdempsky

When we perform escape analysis on a call site to a function that was previously analyzed, the analysis is done context sensitively. We take note of the arguments and how they flow to results, according to the callee's previous analysis.

But within a batch of mutually recursive functions, we handle calls by directly flowing arguments to other functions and directly flowing results to where they're used. This has a consequence of making the analysis context-insensitive.

For example, in the package below, when inlining is disabled, we report that p leaks to the heap, rather than to the result of f. This imprecision happens because we see p flows to the result of f, and then flows to the result of g (thus escaping).

package p

func f(p *int) *int {
	g()
	return p
}

func g() *int {
	return f(new(int))
}

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions