The annotation types the slot, so `x: c_int32 = 0` is an i32 where the
literal alone would give an i64; the store goes through the same
handle_variable_assignment plain assignment uses. A bare `x: T` makes the
slot and binds nothing.
The already-bound and global-shadowing bookkeeping that Assign allocation did
inline moves into _bind_name, which both statements now call.
ctx_field_into_slots.py stores 8-, 32- and 64-bit sk_buff fields into
locals declared at every width and into struct fields of every width,
with IR assertions on the slot widths and the truncation before each
store. It is the compact form of a 52-case matrix (four field widths,
nine local and four struct-field destinations) compiled on master and
here: every case compiles, nothing sign-extends a field on the way in,
and where master compiled the IR is identical except where master put a
narrow local in a 64-bit slot. c_bool.py covers the local, struct field,
map value and global.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
c_bool was missing from the ctypes table, so c_bool(5) was an unknown
call, its slot was never allocated, and the error read "Undefined
variable". It is C's _Bool: one bit, like the True/False locals, never
negative, and a value narrows to it by comparing with zero, which the
signedness rules already apply to 1-bit types. It works as a local, a
struct field, a map value and a global; in BTF it is a one-byte _Bool.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Two places took an integer's width as 32 or 64 bits. Ten sites computed
byte sizes as width // 8 (alignment, struct layout, globals), which is
zero for a 1-bit type; they now share byte_size(), which rounds up to
whole bytes. And debug info described every map key or value, and every
struct field, that was not 32 bits wide as unsigned long long: a c_uint8
or c_uint16 map value was declared 8 bytes wide in BTF, so the kernel
copied 8 bytes from a smaller slot. get_int_type() now gives the real
width and sign everywhere, globals included.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The printk formatter accepted 64- and 32-bit integers only and raised for
anything else. That went unnoticed while c_uint16(0) and friends silently
made 64-bit slots; with those slots now their declared width, printing
any 8- or 16-bit local failed. Every integer argument is already widened
to 64 bits per its sign before the call, so the 64-bit format fits every
width, and the sign now chooses %lld or %llu (an unsigned value above
INT_MAX printed as negative before).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
get_typed_operand fell through its Name branch for a name that is not a
local, a global or a vmlinux constant, and raised the generic
"Unsupported operand type" meant for unknown node kinds. Since return
goes through it, forgetting `from vmlinux import XDP_PASS` produced that
message; it says "Undefined variable XDP_PASS" now, like every other
read.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
helpers.py defined all five and return_utils mapped them, but only
XDP_DROP and XDP_PASS were exported, so the xdp_tx port had to import
XDP_TX from vmlinux and live under vmlinux/, skipped on any host without
a generated module. It imports from pythonbpf.helper and lives under
xdp/ now, returning XDP_TX bare like its siblings and the C original,
which is the shape the return fast path resolves without vmlinux.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Every xfail is strict with raises=Exception, so a verifier-level
negative fixture counted any rejection as the expected one, including
one caused by a codegen regression, or by bpftool failing. A verifier
entry may now carry match = "..."; the harness attaches it as a
verifier_match marker and test_kernel_verifier fails, through
pytest.fail (not swallowed by raises=Exception), when the program is
rejected for any other reason. xdp_devmap_helpers pins its documented
"invalid bpf_context access".
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
process_array_map was a stub raising NotImplementedError while ArrayMap
was exported from pythonbpf.maps as if usable. The lowering is the hash
map's with a different type constant: the same lookup/update/delete
helpers, and the kernel fixes the key at a 4-byte index. The lookup
allocation path accepts ARRAY alongside HASH, the audit tool lists
ARRAY as supported, and the array_map_lookup_update case is a passing
test now instead of a strict xfail.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The Field branch of handle_variable_assignment rebuilt the field's type
by name and duplicated the integer convert() path, and ctypes_to_ir
raises NotImplementedError for a pointer or array ctype before the
logged error is reached. An integer Field is now normalised to its
declared IntTy (field_int_type) before the integer path, in both
variable and struct-field assignment, so ctx fields go through the same
convert() call as everything else; the Field branch keeps only the
non-integer error.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
_allocate_for_call recognised only c_int32, c_int64, c_uint32, c_uint64
and c_void_p, so queue = c_uint16(0) fell through to an i64 slot and a
later store of a u32 field into it never narrowed. Any integer ctypes
constructor now declares a slot of its width, which is what the
ctx_field_narrow_store test claimed to pin; the IR assertion pins it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- The subprog_call pattern also matched SEC("?..."), so every
non-autoloaded program counted as a BPF-to-BPF call blocker, in
contradiction with the soft rule for the same syntax.
- The kfunc pattern matched any bpf_xdp_* or bpf_skb_* call, which are
ordinary helpers (bpf_skb_store_bytes is in SUPPORTED_HELPERS). Only
the kfunc families keep those prefixes; an unsupported helper is still
a hard blocker, classified as one.
- strip_comments removed // inside string literals, truncating section
names like SEC("uprobe//proc/self/exe:func") and classifying the file
as a shim. Strings are matched first and kept.
- Every bpf_map_* helper not in SUPPORTED_HELPERS was dropped before the
unsupported-helper test, so bpf_map_push_elem and friends never showed
up as blockers. The membership test classifies them now.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
except Exception turned every import-time defect in the generated module
into a skip of every vmlinux test, so CI could pass with no vmlinux
coverage. ImportError (no module) skips; anything else propagates.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
veristat_foo (three socket programs) is clean. test_perf_link,
test_enable_stats and test_cgroup_link count with __sync_fetch_and_add, which
becomes a plain `x += 1` tagged WORKAROUND(atomics) for a mechanical sweep
once atomics exist. connect4_dropper compares against bpf_htons(port), written
out as shifts on the low 16 bits. All five pass at IR, llc and verifier level,
and bring perf_event, raw_tracepoint/sys_enter, cgroup_skb/egress and
cgroup/connect4 under test.
The porting notes gain the third batch, the atomics tag, the current blocker
histogram from the checked-in audit tool, and how to re-run it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
The porting assessment was produced by a one-off script that scored every
program under tools/testing/selftests/bpf/progs against the compiler's
envelope; the notes recommended keeping it so the numbers can be regenerated
after each feature lands. This is that script, rebuilt: it strips comments,
skips include-shims and header-only fixtures, and reports per program the
hard blockers (language gaps) and soft flags (porting costs), with a
histogram and a near-miss listing. The helper, map and construct lists at
the top are the envelope and are maintained by hand.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
Every program on the selftest audit's Tier 1 and Tier 2 lists that the compiler
can express today: xdp_dummy, priv_prog, test_xdp_link, xdp_tx, tc_dummy,
test_tc_bpf, cgroup_mprog, cgroup_skb_direct_packet_access, test_signed_loader,
test_signed_loader_data, test_netfilter_link_attach, kprobe_multi_empty,
uprobe_multi_bench, uprobe_multi_usdt, test_link_pinning and
test_xdp_devmap_helpers. Fifteen pass at every level, bringing tc, tcx,
cgroup/getsockopt, cgroup_skb, socket, netfilter, kprobe.multi, uprobe.multi,
usdt and tp_btf program types under test for the first time.
test_xdp_devmap_helpers is a negative fixture upstream: reading egress_ifindex
is only legal with expected_attach_type = BPF_XDP_DEVMAP and the driver asserts
the plain load fails. It is a strict verifier-level xfail here for the same
reason, until expected_attach_type can be expressed.
The porting notes record the batch and why each remaining program on the two
lists is still out of reach.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
A sub-register context field is loaded zero-extended to i64, and the
assignment path accepted it only into a 64-bit slot or one whose type was
exactly the field's declared type. The second case never worked in practice:
`data_end = skb.data_end` into a c_uint32 global died in llvmlite with
"cannot store i64 to i32*" because the value was still i64.
Route the store through convert(), sizing from the physical value and signing
from the field, like every other integer store since the signedness work: a
no-op into an i64 slot, a trunc into anything narrower. Found by porting
cgroup_skb_direct_packet_access.c, which is that exact statement.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
The selftest spike substituted a one-entry HashMap for every upstream global
because PythonBPF had no global variable support. Integer-scalar @bpfglobal
support has since landed, so the three affected ports now declare the upstream
globals directly: get_cgroup_id reads expected_pid and writes cg_id, autoattach
shares prog1_called/prog2_called between two programs, and perf_skip reads ip.
perf_skip stays a strict xfail on the nested ctx.regs.ip access.
Update the tests README and porting notes accordingly; the WORKAROUND tag no
longer exists in the tree.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
xdp_md.data/data_end/data_meta and __sk_buff.data/data_end are u32 in
C and packet pointers to the verifier, so arithmetic on them directly
is rejected as 32-bit pointer arithmetic, for C and for us alike. A
TODO at the point where a field's rank is decided describes the planned
fix (64-bit pointer rank for those fields, no cast needed), and the
user guide documents the workaround until then: copy to a local or cast
through c_void_p.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
xdp_md.data is a u32 in C, but the verifier tracks it as a packet
pointer and rejects 32-bit arithmetic on it: "R0 32-bit pointer
arithmetic prohibited", the same for a C program, which is why C casts
it through (void *)(long) first. The u32 ranking the test pins is the
correct one; it just has to be pinned on a field that is a scalar to the
verifier too. ingress_ifindex is.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
One IR-shape case per fix: u32 >>= / //= / %= emit lshr/udiv/urem;
ktime() >> 1 and pid() // 3 emit lshr/udiv; p >> 63 on a c_uint64 map
value is lshr; ctx.data - c_int32 is a u32 subtraction with the
trunc/zext pair rather than a 64-bit one.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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 <noreply@anthropic.com>
- A global's descriptor is built from the loaded value, not from None.
- get_operand_value, the [0] wrapper over get_typed_operand, had no
callers left; removed with its export.
- infer_int_type's map branch names the map's declared value type for
what it is (value_ctype), says that the key argument plays no part,
and applies only to lookup: update and delete return a status, not a
value of the map's type.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Two descriptors were built from the physical value instead of the
declaration. A sub-register vmlinux field is widened to i64 by
load_ctx_field, and its descriptor took that width, so ctx.data - k with
a c_int32 k was a 64-bit subtraction where C makes it a u32 one. A
map-lookup local dereferenced past its slot took the physical pointee
(i64, signed by default) and dropped the map's declared value ctype kept
in the symbol's metadata, so p >> 63 on a c_uint64 value was an ashr.
Both now read the declaration; the physical width still comes from the
value, as everywhere else.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The registry types ktime, pid, uid, random, cgroup_id and smp_processor_id
as unsigned, and undeclared locals initialised from them already took
that sign. The expression value did not: each emitter returns
(value, plain i64), so ktime() >> 1 was an ashr and pid() // 3 an sdiv.
The dispatcher now substitutes the registered descriptor when the widths
agree, in one place instead of in every emitter.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A bool is ir.IntType(1), so convert() handled it as a 1-bit integer: a
bool slot's plain descriptor read as signed and True sign-extended to
-1 on the way out, and an integer narrowed to a bool by truncation, so
2 became false. Both predate this branch. C widens a bool to 0 or 1 and
narrows to it with != 0, and Python's truthiness agrees on the second.
signedness() now answers unsigned for any 1-bit integer whatever it is
wrapped in, convert() narrows to width 1 with icmp ne 0, and a bool
constant's slot carries the unsigned descriptor like the comparison
results already do.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- process_stmt now raises NotImplementedError on an unsupported statement
instead of warning: a dropped statement silently changes what the
program means (a for/while loop compiled to nothing).
- failing_tests/loops/: 8 xfail tests for for/while/break/continue/nested
loops and map iteration
- failing_tests/assign/annotated_assign.py: xfail for `x: c_int64 = 0`
(ast.AnnAssign is not handled)
return/map_value.py is the C shape `if (p) return *p;`; return_struct.py
is the type error convert() now raises; vmlinux/enum_rank.py pins the
u32 trunc/zext pair for `XDP_PASS - k`. test_signedness_ir.py takes
paths under passing_tests so it can assert on all three, and skips the
vmlinux case when vmlinux.py is not importable, as the harness does.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
An enum constant has type int in C whatever the enum's underlying type
is; clang emits `sub nsw i32` + sext for `XDP_PASS - k` and reserves the
enum's u32 for variables of the enum type. The vmlinux handler was
typing constants as i64, which made `XDP_PASS - k` with an unsigned k a
signed 64-bit operation instead of C's u32 one. The constant's C rank
is now decided once, in type_deducer.int_literal_type, shared by
literals and enum constants, and the handler returns it as the
descriptor so both operand typing and local inference read it from
the source.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A pointer used where a value is expected is dereferenced to it, with a
null check, in helper arguments, printk arguments, binary-operation
operands and comparisons, all through deref_to_depth. return was the
one consumer that never joined that convention, so `return p` on a map
lookup emitted `ret i64*` and left it to llc to reject. handle_return
now goes through get_typed_operand, which is that path, and converts
the result to the declared return type like the augmented-assignment
store does.
convert() no longer passes a non-integer through silently: every
caller either checks both sides or is on an integer-only path, so what
reaches that branch is a type error, and it is raised with both types
named instead of surfacing from llc with an IR line number. Returning
a struct value is the case that now fails at compile time.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
failing_tests/vmlinux/assignment_handling.py pinned exactly this gap
("This gives an error, but / this does not"); it moves to the passing
suite and its xfail entry goes. enum_to_local.py adds the C shape
`int act = XDP_PASS; if (...) act = XDP_DROP; return act;`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Every read of a bare name resolves local, then BPF global, then vmlinux
enum constant, except the allocation pass's variable-to-variable path,
which stopped after the globals and rejected `act = XDP_PASS` with
"source variable not found", while `act = XDP_PASS + 0` compiled through
the binop path. The error text pointed the wrong way: it is the target
that needs a stack slot, and the pass could not type it. An enum
constant is an immediate with no storage of its own, so the target gets
the i64 slot a literal gets, and the constant is folded at the store.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Review on the previous round: the UnboundLocalError-shaped messages said
in five lines what one says, and the ast.Global branch of process_stmt
explained itself at length for a no-op. Both messages now name the
problem and the fix and stop; the branch keeps its debug log only.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>