From e35d4c0327db00585b95ce63012daaadfe4f2050 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 24 Sep 2026 19:30:37 +0530 Subject: [PATCH] Core: Pass the result sign to the operator in augmented assignment The binary-operation path chooses sdiv/udiv, srem/urem and ashr/lshr from the promoted type; the augmented-assignment path computed the same promoted type and then called apply_binop without it, so u32 >>= 4 was an ashr and u32 //= 3 an sdiv. Same call as the binop path now. Co-Authored-By: Claude Fable 5.1 --- pythonbpf/functions/functions_pass.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 7da4a68..382ef38 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -6,7 +6,7 @@ import logging from pythonbpf.helper import ( HelperHandlerRegistry, ) -from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes +from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes, signedness from pythonbpf.expr import ( eval_expr, handle_expr, @@ -283,7 +283,9 @@ def handle_aug_assign(func, compilation_context, builder, stmt, local_sym_tab): current = to_promoted(builder, current, slot_type, result_ty) rhs = to_promoted(builder, rhs, rhs_ty, result_ty) result = canonicalise( - builder, apply_binop(builder, stmt.op, current, rhs), result_ty + builder, + apply_binop(builder, stmt.op, current, rhs, signedness(result_ty)), + result_ty, ) builder.store(convert(builder, result, result_ty, slot_type), slot)