Skip to content

ci: add clang-tidy gate and libFuzzer target - #53

Merged
sentomk merged 1 commit into
mainfrom
ci/tidy-and-fuzz
Aug 1, 2026
Merged

ci: add clang-tidy gate and libFuzzer target#53
sentomk merged 1 commit into
mainfrom
ci/tidy-and-fuzz

Conversation

@sentomk

@sentomk sentomk commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

Add the two missing verification layers: static analysis via clang-tidy (warnings-as-errors gate on tests + samples) and fuzzing via a libFuzzer target with oracle comparison. Adding clang-tidy immediately paid off — it surfaced two real latent bugs in the evaluation path.

Changes

  • .clang-tidy: bugprone-*, clang-analyzer-*, performance-*, portability-*, concurrency-*, scoped to include/ptn/, WarningsAsErrors: '*'. Three checks disabled with documented rationale (CRTP mixin style, metaprogramming branch clones, swappable-parameter noise).
  • .github/workflows/clang-tidy.yml: runs the config on every test/sample TU (json_dispatch excluded — needs nlohmann/json).
  • Fixes from the first scan:
    • guard.hpp eval(bin_expr) and eval.hpp invoke_from_tuple_impl: unsequenced double std::forward of the same tuple (bugprone-use-after-move) — now evaluate through lvalue, which is also semantically right for read-only paths.
    • performance-enum-size: explicit std::uint8_t for range_mode (shrinks range_predicate by 3 bytes) and 8 compile-time enums; fwd declarations synced.
    • structural.hpp: has_guarded_pattern forwarding constructor constrained so it cannot hide copy/move ctors.
  • fuzz/ptn_fuzz_match.cpp: oracle-based target — five batteries (literal dispatch, guards, structural, variant, combinators) comparing patternia against reference implementations; divergence traps.
  • fuzz/CMakeLists.txt + PTN_BUILD_FUZZ option (Clang-only, FATAL_ERROR otherwise); Windows CRT pinning handled (MSVC_RUNTIME_LIBRARY MultiThreaded for clang_rt.fuzzer's MT_StaticRelease).
  • .github/workflows/fuzz.yml: 180s smoke per PR/push, 900s weekly deep run, crash artifacts uploaded on failure.

Testing

  • clang-tidy clean on all 16 test/sample TUs scanned locally (Clang 20).
  • Local fuzz: 8.27M executions in 45s (ASan, Windows), zero divergence, zero sanitizer reports, ~180k exec/s.
  • Full suite: 204/204 passing.

Follow-ups (repo settings, outside this PR)

  • Add clang-tidy and fuzz to the branch protection required checks once both workflows have proven stable on main.
  • Consider a growing seed corpus under fuzz/corpus/ once the first interesting inputs accumulate.

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Problem
- The project had no static analysis beyond clang-format and no
  fuzzing, so runtime evaluation paths (binding, dispatch,
  structural extraction) were only covered by fixed test cases.

Implementation
- Add .clang-tidy (bugprone/clang-analyzer/performance/portability/
  concurrency, headers-only scope, warnings-as-errors) and a
  clang-tidy workflow running it on tests and samples.
- Fix the findings it surfaced: two unsequenced double-forwards in
  guard/tuple evaluation (bugprone-use-after-move), missing enum
  underlying types (performance-enum-size), and an unconstrained
  forwarding constructor (bugprone-forwarding-reference-overload).
- Add fuzz/ptn_fuzz_match: oracle-based libFuzzer target comparing
  literal, guard, structural, variant, and combinator evaluation
  against reference implementations, behind PTN_BUILD_FUZZ.
- Add a fuzz workflow: 180s smoke on PR/push, 900s weekly deep
  run, crash artifacts uploaded on failure.

Tests
- clang-tidy is clean on all test and sample TUs (json_dispatch
  excluded: needs nlohmann/json).
- Local fuzz run: 8.27M executions in 45s with ASan on Windows,
  no divergence, no sanitizer reports.
- Full suite: 204/204.
@sentomk
sentomk merged commit 072828e into main Aug 1, 2026
24 checks passed
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