Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mdempsky opened this issue Sep 7, 2023 · 1 comment
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

mdempsky commented Sep 7, 2023

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))
}
@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 7, 2023
@mdempsky mdempsky added this to the Go1.22 milestone Sep 7, 2023
@mdempsky mdempsky self-assigned this Sep 7, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 7, 2023
@gopherbot
Copy link

Change https://go.dev/cl/526520 mentions this issue: cmd/compile/internal/escape: handle interface method calls better

@gopherbot gopherbot modified the milestones: Go1.22, Go1.23 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

2 participants