-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[venom]: invalid jump error (#4214)
fix an issue where `ret` would generate a jump to an invalid location because the stack is not clean. the solution is to always pop instruction outputs which are not used. note this leads to a slight performance regression (roughly 0.07% bytecode size), since `POP`s are always generated, even in cases when the stack does not need to be cleaned (e.g. before `STOP`). --------- Co-authored-by: Charles Cooper <[email protected]> Co-authored-by: Harry Kalogirou <[email protected]>
- Loading branch information
1 parent
03095ce
commit f7b8e93
Showing
3 changed files
with
24 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from vyper.compiler.settings import OptimizationLevel | ||
from vyper.venom import generate_assembly_experimental | ||
from vyper.venom.context import IRContext | ||
|
||
|
||
def test_cleanup_stack(): | ||
ctx = IRContext() | ||
fn = ctx.create_function("test") | ||
bb = fn.get_basic_block() | ||
ret_val = bb.append_instruction("param") | ||
op = bb.append_instruction("store", 10) | ||
bb.append_instruction("add", op, op) | ||
bb.append_instruction("ret", ret_val) | ||
|
||
asm = generate_assembly_experimental(ctx, optimize=OptimizationLevel.GAS) | ||
assert asm == ["PUSH1", 10, "DUP1", "ADD", "POP", "JUMP"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters