mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
Core: Route every integer widening and narrowing through convert()
The same widen-to-i64 / truncate-to-slot logic was written out by hand in six places: local assignment, struct-field assignment, augmented assignment, helper-argument temporaries, binary-operation operands, and the comparison normaliser. Each now calls type_normalization.convert, which is the single point where the sign decides between zext and sext. Across the 67-program corpus this changes exactly one emitted instruction, and it is a correction rather than a regression: augmented assignment on a c_uint32 struct field now widens the field's current value with zext instead of sext, because that slot's descriptor already carries its sign from ctypes_to_ir. Every other site still sees plain (signed-by-default) descriptors and is byte-identical. The remaining hand-written widenings -- the printk formatter, the vmlinux field loader, return handling -- have their own rules and are migrated together with the sign sources. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
This commit is contained in:
@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from llvmlite import ir
|
||||
from pythonbpf.expr import (
|
||||
convert,
|
||||
eval_expr,
|
||||
access_struct_field,
|
||||
)
|
||||
@ -134,12 +135,8 @@ def get_or_create_ptr_from_arg(
|
||||
local_sym_tab, expected_type
|
||||
)
|
||||
logger.info(f"Using temp variable '{temp_name}' for expression result")
|
||||
if (
|
||||
isinstance(val.type, ir.IntType)
|
||||
and expected_type
|
||||
and val.type.width > expected_type.width
|
||||
):
|
||||
val = builder.trunc(val, expected_type)
|
||||
if expected_type is not None and isinstance(expected_type, ir.IntType):
|
||||
val = convert(builder, val, val.type, expected_type)
|
||||
builder.store(val, ptr)
|
||||
|
||||
# NOTE: For char arrays, also return size
|
||||
|
||||
Reference in New Issue
Block a user