diff --git a/vyper/codegen/context.py b/vyper/codegen/context.py index 7995b7b9f5..9562db7f03 100644 --- a/vyper/codegen/context.py +++ b/vyper/codegen/context.py @@ -35,6 +35,9 @@ class Alloca: _id: int + # special metadata for calloca. hint for venom to tie calloca to call site. + _callsite: Optional[str] = None + def __post_init__(self): assert self.typ.memory_bytes_required == self.size diff --git a/vyper/codegen/self_call.py b/vyper/codegen/self_call.py index 6fe44c69a4..9864722204 100644 --- a/vyper/codegen/self_call.py +++ b/vyper/codegen/self_call.py @@ -1,4 +1,5 @@ import copy +import dataclasses from vyper.codegen.core import _freshname, eval_once_check, make_setter from vyper.codegen.ir_node import IRnode @@ -81,6 +82,7 @@ def ir_for_self_call(stmt_expr, context): continue newname = var.pos.replace("$palloca", "$calloca") var.pos = newname + alloca = dataclasses.replace(alloca, _callsite=return_label) irnode = var.as_ir_node() irnode.passthrough_metadata["alloca"] = alloca arg_items.append(irnode) diff --git a/vyper/venom/ir_node_to_venom.py b/vyper/venom/ir_node_to_venom.py index 0737f2a9be..763f0f3103 100644 --- a/vyper/venom/ir_node_to_venom.py +++ b/vyper/venom/ir_node_to_venom.py @@ -551,8 +551,10 @@ def emit_body_blocks(): elif ir.value.startswith("$calloca"): alloca = ir.passthrough_metadata["alloca"] if alloca._id not in _alloca_table: + assert alloca._callsite is not None + callsite = IRLabel(alloca._callsite) ptr = fn.get_basic_block().append_instruction( - "calloca", alloca.offset, alloca.size, alloca._id + "calloca", alloca.offset, alloca.size, alloca._id, callsite ) _alloca_table[alloca._id] = ptr return _alloca_table[alloca._id]