Tools: Stop counting plain loops as a hard blocker in the selftest audit

for/while lower since #106. The iterator loops (bpf_for, bpf_repeat) and the
bpf_loop helper do not, so they keep a hard label of their own, and a
do { } while (0) macro is no longer read as a loop. Against bpf-next 5714ca8
the programs with no hard blocker go from 29 to 39.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pragyansh Chaturvedi
2026-10-09 01:54:13 +05:30
parent ec5d72fdbe
commit 8907fd511a

View File

@ -15,7 +15,7 @@ negatives in both directions, and the envelope it encodes (the helper, map and
construct lists below) must be kept in step with the compiler by hand. Re-run construct lists below) must be kept in step with the compiler by hand. Re-run
it after a feature lands to see what the feature unlocked. The lists were last it after a feature lands to see what the feature unlocked. The lists were last
reconciled against pythonbpf/helper and pythonbpf/maps when scalar @bpfglobal reconciled against pythonbpf/helper and pythonbpf/maps when scalar @bpfglobal
support and integer signedness merged. support, integer signedness and loops merged.
""" """
import argparse import argparse
@ -70,7 +70,10 @@ NOT_HELPERS = {
# cost a careful rewrite can absorb). Order does not matter. # cost a careful rewrite can absorb). Order does not matter.
PATTERNS = [ PATTERNS = [
# control flow # control flow
("loop", "hard", r"\b(for|while)\s*\(|\bbpf_for\b|\bbpf_repeat\b|\bbpf_loop\s*\("), # plain for/while lower since loops landed (#106); `do { } while (0)` is a
# macro idiom, not a loop. Iterator loops and the bpf_loop helper are not.
("open_coded_loop", "hard", r"\bbpf_for(_each)?\b|\bbpf_repeat\b|\bbpf_loop\s*\("),
("do_while", "soft", r"\}\s*while\s*\((?!\s*0\s*\))"),
("goto", "hard", r"\bgoto\s+\w+"), ("goto", "hard", r"\bgoto\s+\w+"),
("switch", "hard", r"\bswitch\s*\("), ("switch", "hard", r"\bswitch\s*\("),
("ternary", "soft", r"\?[^?:]*:"), ("ternary", "soft", r"\?[^?:]*:"),