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

Named return value sidesteps "unsafe stack variable returned" #3539

Open
thetarnav opened this issue May 5, 2024 · 2 comments
Open

Named return value sidesteps "unsafe stack variable returned" #3539

thetarnav opened this issue May 5, 2024 · 2 comments

Comments

@thetarnav
Copy link
Sponsor Contributor

Named return value sidesteps "unsafe stack variable returned"

code

foo :: proc () -> ^int {
	v: int
	return &v // It is unsafe to return the address of a local variable ('&v') from a procedure, as it uses the current stack frame's memory
}

bar :: proc () -> (p: ^int) {
	v: int
	p = &v
	return // no error
}

report

	Odin:    dev-2024-05:1e5267c8e
	OS:      Ubuntu 22.04.4 LTS, Linux 6.5.0-28-generic
	CPU:     Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
	RAM:     7631 MiB
	Backend: LLVM 17.0.6
@gingerBill
Copy link
Member

This is extremely hard to check for because of how the compiler is set up.

@JesseRMeyer
Copy link

Worth tracking the issue anyway as a known deficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants