Skip to content

nix: add static analysis infrastructure#1

Open
randomizedcoder wants to merge 1 commit intopr/nix-bpf-compat-samplesfrom
pr/nix-static-analysis
Open

nix: add static analysis infrastructure#1
randomizedcoder wants to merge 1 commit intopr/nix-bpf-compat-samplesfrom
pr/nix-static-analysis

Conversation

@randomizedcoder
Copy link
Copy Markdown
Owner

Summary

  • Port static analysis framework from the reference Nix implementation, adapted for XDP2's C codebase and Make-based build system
  • 8 analysis tools at 3 levels: quick (clang-tidy + cppcheck), standard (+ flawfinder, clang-analyzer, gcc-warnings), deep (+ gcc-analyzer, semgrep, sanitizers)
  • Compilation database generated by parsing make V=1 VERBOSE=1 output (bear's LD_PRELOAD and compiledb both fail in Nix sandbox)
  • Python triage system with exemptions for cppcheck tool limitations and idiomatic C patterns (documented in EXEMPTIONS.md)

Results (analysis-quick): 18,108 raw clang-tidy + 202 cppcheck → 14 high-confidence findings after triage.

Stacks on top of PR xdp2-dev#13 (pr/nix-bpf-compat-samplesxdp2-dev:num_args).

Test plan

  • nix eval passes for all 11 analysis targets
  • nix build .#analysis-quick — clang-tidy (18,108) + cppcheck (202), 14 high-confidence
  • nix build .#analysis-standard — + flawfinder (305), clang-analyzer (141), gcc-warnings (111)
  • nix build .#analysis-flawfinder — 305 findings
  • nix build .#analysis-semgrep — 56 findings
  • nix build .#analysis-sanitizers — builds with ASan+UBSan
  • Existing targets (xdp2, xdp2-debug, tests.all) unaffected
  • make analysis convenience target

🤖 Generated with Claude Code

Port static analysis framework from the reference Nix implementation,
adapted for XDP2's C codebase and Make-based build system.

8 analysis tools at 3 levels:
- quick: clang-tidy + cppcheck
- standard: + flawfinder, clang-analyzer, gcc-warnings
- deep: + gcc-analyzer, semgrep, sanitizers

Compilation database generated by parsing `make V=1 VERBOSE=1` output
with a custom Python script, since bear's LD_PRELOAD fails in the Nix
sandbox and compiledb doesn't recognize Nix wrapper compiler paths.

Python triage system aggregates, deduplicates, and prioritizes findings
across all tools. Exemptions documented in EXEMPTIONS.md cover cppcheck
tool limitations (macro parsing, void pointer arithmetic, container_of
patterns) and high-volume style checks (narrowing conversions, reserved
identifiers, assignment-in-if) that are intentional in C networking code.

Results (analysis-quick):
  clang-tidy:  18,108 raw → 3,653 after triage
  cppcheck:    202 raw
  triage:      14 high-confidence findings

Usage:
  nix build .#analysis-quick
  nix build .#analysis-standard
  nix build .#analysis-deep
  make analysis

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant