From 6bce29b90f397c1b8a1539550c3cce5420cbccf0 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Sun, 12 Oct 2025 00:37:57 +0530 Subject: [PATCH] Allocate scratch space for temp vars at the end of allocate_mem --- pythonbpf/functions/functions_pass.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 07fc9d4..1d23d47 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -425,6 +425,7 @@ def allocate_mem( max_temps_needed = max(max_temps_needed, temps_needed) for stmt in body: + update_max_temps_for_stmt(stmt) has_metadata = False if isinstance(stmt, ast.If): if stmt.body: @@ -545,6 +546,13 @@ def allocate_mem( if double_alloc: local_sym_tab[f"{var_name}_tmp"] = LocalSymbol(var_tmp, tmp_ir_type) + + logger.info(f"Temporary scratch space needed for calls: {max_temps_needed}") + for i in range(max_temps_needed): + temp_var = builder.alloca(ir.IntType(64), name=f"__helper_temp_{i}") + temp_var.align = 8 + local_sym_tab[f"__helper_temp_{i}"] = LocalSymbol(temp_var, ir.IntType(64)) + return local_sym_tab