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

Pop for loop values from stack prior to returning #2110

Merged
merged 3 commits into from
Jul 16, 2020

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Fix an issue causing a bad jumpdest when returning from inside a for loop.

During a for loop the stack contains the iterator value and a callback pointer to the start of the loop. When a loop is completed, or exitted via break, each of these values is popped off. A return statement inside a for loop was missing these pops, leaving unexpected values on the stack after returning.

This is only problematic when the return in a for loop happens at least 2 internal calls deep, because the callback pointer for each internal function is also placed on the stack. As such, the attempt to return from the next internal function would instead use the for loop iterator value as it's destination - resulting in a bad jumpdest.

How I did it

To fix this issue, I've added a new LLL macro exit_repeater which adds 2 POP instructions for each active for loop prior to the return jump. This macro is added whenever a return statement is encountered within a for loop.

How to verify it

Run the tests. I've added several cases to verify that the behavior is now working as expected.

Description for the changelog

Cute Animal Picture

image

@fubuloubu fubuloubu merged commit a1d92e5 into vyperlang:master Jul 16, 2020
@iamdefinitelyahuman iamdefinitelyahuman deleted the fix-return-in-loop branch July 16, 2020 20:28
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

Successfully merging this pull request may close these issues.

2 participants