Skip to content

Commit 11850d1

Browse files
field check in allocation pass
1 parent 9ee821c commit 11850d1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

pythonbpf/allocation_pass.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,6 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
337337
VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
338338
)
339339
field_ir, field = field_type
340-
# TODO: For now, we only support integer type allocations.
341-
# This always assumes first argument of function to be the context struct
342-
# base_ptr = builder.function.args[0]
343-
# local_sym_tab[
344-
# struct_var
345-
# ].var = base_ptr # This is repurposing of var to store the pointer of the base type
346-
# local_sym_tab[struct_var].ir_type = field_ir
347340

348341
# Determine the actual IR type based on the field's type
349342
actual_ir_type = None
@@ -398,12 +391,12 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
398391
)
399392
actual_ir_type = ir.IntType(64)
400393

401-
# Allocate with the actual IR type, not the GlobalVariable
394+
# Allocate with the actual IR type
402395
var = _allocate_with_type(builder, var_name, actual_ir_type)
403-
local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field)
396+
local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field) # <-- Store Field metadata
404397

405398
logger.info(
406-
f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}"
399+
f"Pre-allocated {var_name} as {actual_ir_type} from vmlinux struct {vmlinux_struct_name}.{field_name}"
407400
)
408401
return
409402
else:

pythonbpf/expr/expr_pass.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from pythonbpf.vmlinux_parser.assignment_info import Field
1616
from .vmlinux_registry import VmlinuxHandlerRegistry
17+
from ..vmlinux_parser.dependency_node import Field
1718

1819
logger: Logger = logging.getLogger(__name__)
1920

@@ -89,8 +90,16 @@ def _handle_attribute_expr(
8990
return vmlinux_result
9091
else:
9192
raise RuntimeError("Vmlinux struct did not process successfully")
92-
metadata = structs_sym_tab[var_metadata]
93-
if attr_name in metadata.fields:
93+
94+
elif isinstance(var_metadata, Field):
95+
logger.error(
96+
f"Cannot access field '{attr_name}' on already-loaded field value '{var_name}'"
97+
)
98+
return None
99+
100+
# Regular user-defined struct
101+
metadata = structs_sym_tab.get(var_metadata)
102+
if metadata and attr_name in metadata.fields:
94103
gep = metadata.gep(builder, var_ptr, attr_name)
95104
val = builder.load(gep)
96105
field_type = metadata.field_type(attr_name)

0 commit comments

Comments
 (0)