mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
Core: Type comparison and boolean results as unsigned i1
A comparison's descriptor was a plain i1, which reads as signed, so storing or returning a truth value would sign-extend true to -1. C's relational operators yield int 0 or 1; give the results an unsigned descriptor so any widening zero-extends. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
This commit is contained in:
@ -421,7 +421,7 @@ def _handle_unary_op(
|
||||
if isinstance(expr.op, ast.Not):
|
||||
true_const = ir.Constant(ir.IntType(1), 1)
|
||||
result = builder.xor(convert_to_bool(builder, operand), true_const)
|
||||
return result, ir.IntType(1)
|
||||
return result, IntTy(1, False)
|
||||
elif isinstance(expr.op, ast.USub):
|
||||
if isinstance(operand, ir.Constant) and isinstance(operand.constant, int):
|
||||
# -2 parses as USub(Constant 2); fold it so it is a literal like
|
||||
@ -491,7 +491,7 @@ def _handle_and_op(func, builder, expr, local_sym_tab, compilation_context):
|
||||
phi.add_incoming(val, block)
|
||||
|
||||
logger.debug(f"Generated 'and' with {len(incoming_values)} incoming values")
|
||||
return phi, ir.IntType(1)
|
||||
return phi, IntTy(1, False)
|
||||
|
||||
|
||||
def _handle_or_op(func, builder, expr, local_sym_tab, compilation_context):
|
||||
@ -544,7 +544,7 @@ def _handle_or_op(func, builder, expr, local_sym_tab, compilation_context):
|
||||
phi.add_incoming(val, block)
|
||||
|
||||
logger.debug(f"Generated 'or' with {len(incoming_values)} incoming values")
|
||||
return phi, ir.IntType(1)
|
||||
return phi, IntTy(1, False)
|
||||
|
||||
|
||||
def _handle_boolean_op(
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from llvmlite import ir
|
||||
from .ir_ops import deref_to_depth
|
||||
from pythonbpf.type_deducer import signedness
|
||||
from pythonbpf.type_deducer import IntTy, signedness
|
||||
from .operators import COMPARISON_OPS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -128,4 +128,4 @@ def handle_comparator(func, builder, op, lhs, rhs, signed=True):
|
||||
icmp = builder.icmp_signed if signed else builder.icmp_unsigned
|
||||
result = icmp(predicate, lhs, rhs)
|
||||
logger.debug(f"Comparison result: {result}")
|
||||
return result, ir.IntType(1)
|
||||
return result, IntTy(1, False)
|
||||
|
||||
Reference in New Issue
Block a user