From 26604b98462f479ddb3cbacff55512a4e49114f4 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 24 Sep 2026 19:27:53 +0530 Subject: [PATCH] Core: Give a helper call's value the sign its registry entry declares The registry types ktime, pid, uid, random, cgroup_id and smp_processor_id as unsigned, and undeclared locals initialised from them already took that sign. The expression value did not: each emitter returns (value, plain i64), so ktime() >> 1 was an ashr and pid() // 3 an sdiv. The dispatcher now substitutes the registered descriptor when the widths agree, in one place instead of in every emitter. Co-Authored-By: Claude Fable 5.1 --- pythonbpf/helper/bpf_helper_handler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pythonbpf/helper/bpf_helper_handler.py b/pythonbpf/helper/bpf_helper_handler.py index 631a826..92bb130 100644 --- a/pythonbpf/helper/bpf_helper_handler.py +++ b/pythonbpf/helper/bpf_helper_handler.py @@ -1076,7 +1076,7 @@ def handle_helper_call( raise NotImplementedError( f"Helper function '{method_name}' is not implemented." ) - return handler( + result = handler( call, map_ptr, compilation_context, @@ -1084,6 +1084,19 @@ def handle_helper_call( func, local_sym_tab, ) + # Emitters return (value, plain LLVM type); the registry entry is the + # descriptor that knows the sign. Substitute it once, here, rather + # than in every emitter. + declared = HelperHandlerRegistry.get_return_type(method_name) + if ( + isinstance(result, tuple) + and len(result) == 2 + and isinstance(declared, ir.IntType) + and isinstance(result[1], ir.IntType) + and declared.width == result[1].width + ): + return result[0], declared + return result map_sym_tab = compilation_context.map_sym_tab