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

fix: assembly dead code eliminator #3791

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions vyper/ir/compile_ir.py
Original file line number Diff line number Diff line change
@@ -809,14 +809,18 @@ def _prune_unreachable_code(assembly):
# unreachable
changed = False
i = 0
while i < len(assembly) - 2:
while i < len(assembly) - 1:
instr = assembly[i]
if isinstance(instr, list):
instr = assembly[i][-1]

if assembly[i] in _TERMINAL_OPS and not (
is_symbol(assembly[i + 1]) or isinstance(assembly[i + 1], list)
):
is_terminal = assembly[i] in _TERMINAL_OPS
next_is_jumpdest = (
i + 2 < len(assembly) and is_symbol(assembly[i + 1]) and assembly[i + 2] == "JUMPDEST"
)
next_is_list = isinstance(assembly[i + 1], list)

if is_terminal and not (next_is_jumpdest or next_is_list):
changed = True
del assembly[i + 1]
else:
@@ -1230,7 +1234,6 @@ def assembly_to_evm_with_symbol_map(assembly, pc_ofst=0, insert_compiler_metadat
if is_symbol_map_indicator(assembly[i + 1]):
# Don't increment pc as the symbol itself doesn't go into code
if item in symbol_map:
print(assembly)
raise CompilerPanic(f"duplicate jumpdest {item}")

symbol_map[item] = pc