From dc9aecf3817fdaa3872234265a7959cc61f06c82 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 3 Sep 2026 07:22:03 +0530 Subject: [PATCH] Core: Coerce integer width when assigning to a struct field handle_struct_field_assignment stored the evaluated value as-is, and since expressions evaluate in i64 that meant any assignment to a sub-64-bit field (dat.hits = 1 with hits: c_uint32) died in llvmlite with "cannot store i64 to i32*". Apply the same implicit widening/truncation the local-assignment path already has. Surfaced by the augmented-assignment struct-field test. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF --- pythonbpf/assign_pass.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pythonbpf/assign_pass.py b/pythonbpf/assign_pass.py index 9939357..c71bd28 100644 --- a/pythonbpf/assign_pass.py +++ b/pythonbpf/assign_pass.py @@ -54,6 +54,14 @@ def handle_struct_field_assignment( logger.info(f"Copied string to char array {var_name}.{field_name}") return + # Same implicit widening/truncation as assignment to a local: expressions + # evaluate in i64, but a field may be narrower. + if isinstance(val_type, ir.IntType) and isinstance(field_type, ir.IntType): + if val_type.width < field_type.width: + val = builder.sext(val, field_type) + elif val_type.width > field_type.width: + val = builder.trunc(val, field_type) + # Regular assignment builder.store(val, field_ptr) logger.info(f"Assigned to struct field {var_name}.{field_name}")