Skip to content

Commit 26604b9

Browse files
r41k0uclaude
andcommitted
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 <noreply@anthropic.com>
1 parent c52a5f5 commit 26604b9

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎pythonbpf/helper/bpf_helper_handler.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,27 @@ def invoke_helper(method_name, map_ptr=None):
10761076
raise NotImplementedError(
10771077
f"Helper function '{method_name}' is not implemented."
10781078
)
1079-
return handler(
1079+
result = handler(
10801080
call,
10811081
map_ptr,
10821082
compilation_context,
10831083
builder,
10841084
func,
10851085
local_sym_tab,
10861086
)
1087+
# Emitters return (value, plain LLVM type); the registry entry is the
1088+
# descriptor that knows the sign. Substitute it once, here, rather
1089+
# than in every emitter.
1090+
declared = HelperHandlerRegistry.get_return_type(method_name)
1091+
if (
1092+
isinstance(result, tuple)
1093+
and len(result) == 2
1094+
and isinstance(declared, ir.IntType)
1095+
and isinstance(result[1], ir.IntType)
1096+
and declared.width == result[1].width
1097+
):
1098+
return result[0], declared
1099+
return result
10871100

10881101
map_sym_tab = compilation_context.map_sym_tab
10891102

0 commit comments

Comments
 (0)