Skip to content

Commit dc9aecf

Browse files
r41k0uclaude
andcommitted
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
1 parent aa321db commit dc9aecf

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎pythonbpf/assign_pass.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def handle_struct_field_assignment(
5454
logger.info(f"Copied string to char array {var_name}.{field_name}")
5555
return
5656

57+
# Same implicit widening/truncation as assignment to a local: expressions
58+
# evaluate in i64, but a field may be narrower.
59+
if isinstance(val_type, ir.IntType) and isinstance(field_type, ir.IntType):
60+
if val_type.width < field_type.width:
61+
val = builder.sext(val, field_type)
62+
elif val_type.width > field_type.width:
63+
val = builder.trunc(val, field_type)
64+
5765
# Regular assignment
5866
builder.store(val, field_ptr)
5967
logger.info(f"Assigned to struct field {var_name}.{field_name}")

0 commit comments

Comments
 (0)