From be05b5d1027aa29788123755c427667529a38f86 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Fri, 3 Oct 2025 19:50:56 +0530 Subject: [PATCH] Allow local symbols to be used within return --- pythonbpf/functions_pass.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pythonbpf/functions_pass.py b/pythonbpf/functions_pass.py index a8f106a..38355ef 100644 --- a/pythonbpf/functions_pass.py +++ b/pythonbpf/functions_pass.py @@ -417,6 +417,19 @@ def process_stmt( ) builder.ret(val[0]) did_return = True + elif isinstance(stmt.value.args[0], ast.Name): + if stmt.value.args[0].id in local_sym_tab: + var = local_sym_tab[stmt.value.args[0].id].var + val = builder.load(var) + if val.type != ret_type: + raise ValueError( + "Return type mismatch: expected" + f"{ret_type}, got {val.type}" + ) + builder.ret(val) + did_return = True + else: + raise ValueError("Failed to evaluate return expression") elif isinstance(stmt.value, ast.Name): if stmt.value.id == "XDP_PASS": builder.ret(ir.Constant(ret_type, 2))