Skip to content

Move CI static analysis and sanitizers to LLVM 22 and add an opt-in clang-tidy pre-commit hook - #182

Merged
philipcraig merged 4 commits into
mainfrom
clang-tidy-22-pin
Aug 27, 2026
Merged

Move CI static analysis and sanitizers to LLVM 22 and add an opt-in clang-tidy pre-commit hook#182
philipcraig merged 4 commits into
mainfrom
clang-tidy-22-pin

Conversation

@philipcraig

@philipcraig philipcraig commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Move the clang-tidy pin from LLVM 21 to 22 in every place it lives: the Clang Tidy and IWYU workflows, docker/Dockerfile (clang-tidy-22 + clang-tidy symlink), and cmake/modules/FindClangTidy.cmake (prefers clang-tidy-22, warns on a major-version mismatch with CI).
  • Add Clang-22 (C++20 and C++23) entries to the cmake.yml build matrix, and fix the Clang-20 entry, which asked setup-clang for version 19 and only worked because the runner image already ships clang-20.
  • Bump google benchmark v1.9.1 → v1.9.5. Clang 22 warns that __COUNTER__ is a C2y extension (-Wc2y-extensions), and benchmark compiles its own sources with -Werror -pedantic-errors, so v1.9.1 failed to build in the new Clang-22 jobs. v1.9.5 suppresses the warning around its __COUNTER__ probe.
  • Add a manual-stage pre-commit hook clang-tidy that runs ./scripts/cmake.sh --debug --clang-tidy, invoked with uv run pre-commit run --hook-stage manual clang-tidy. It is skipped by the default pre-commit run --all-files, so the pre-commit CI job is unaffected.
  • Run the sanitizer jobs (asan+ubsan, tsan, msan) with Clang 22 instead of 19.
  • Document the above in CONTRIBUTING.md.

Why

.clang-tidy already disables cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, which only exists in clang-tidy 22, and clang-format is pinned to 22, while CI analysed with 21. clang-tidy silently ignores unknown check names, so nothing broke, but local and CI runs used different check sets.

Test plan

  • uv run pre-commit validate-config and uv run pre-commit run --all-files pass; the clang-tidy hook is not run at the default stage.
  • uv run pre-commit run --hook-stage manual clang-tidy runs the full build.
  • FindClangTidy.cmake version warning verified with a stub clang-tidy reporting 21.1.6.
  • Local ./scripts/cmake.sh --debug --clean with benchmark v1.9.5: 87/87 tests pass.
  • Clang Tidy workflow passes on LLVM 22 with zero new findings.
  • IWYU workflow builds from the clang_22 branch and passes.
  • New Clang-22 matrix jobs pass (they failed on v1.9.1 before the benchmark bump).
  • Clang-20 matrix jobs pass with Clang 20 actually installed.
  • Sanitizer jobs (asan+ubsan, tsan, msan) pass on Clang 22.
  • docker/Dockerfile change verified in a rebuilt Codespace: clang-tidy resolves to clang-tidy-22 (LLVM 22.1.2), CMake selects it with no version warning, the manual hook passes on a clean build, and an injected in-tree finding is rejected.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QHjiPBayDu7hLZyhcQK3tt

philipcraig and others added 4 commits August 27, 2026 14:21
CI ran clang-tidy 21 while .clang-tidy already referenced a check that
only exists in clang-tidy 22 and clang-format was pinned to 22, so local
and CI runs could disagree on the check set. Move every pin to 22:

- clang-tidy.yml and iwyu.yml: COMPILER_VERSION 22 (IWYU has a clang_22
  branch).
- docker/Dockerfile: install clang-tidy-22 (the unversioned package on
  Ubuntu 26.04 is 21) and symlink it as clang-tidy so CMake finds it.
- FindClangTidy.cmake: prefer clang-tidy-22, and warn at configure time
  when the found major version differs from ClangTidy_EXPECTED_MAJOR_VERSION.
- cmake.yml: add Clang-22 (C++20 and C++23) matrix entries.

Add a manual-stage pre-commit hook that runs the same
`./scripts/cmake.sh --debug --clang-tidy` build as CI, so there is one
documented local invocation without a full build on every commit. Being
manual-stage, it is skipped by `pre-commit run --all-files` in CI.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHjiPBayDu7hLZyhcQK3tt
Clang 22 warns that __COUNTER__ is a C2y extension, and benchmark builds
its own sources with -Werror -pedantic-errors, so v1.9.1 failed to
compile in the new Clang-22 matrix jobs. v1.9.5 suppresses the warning
around its __COUNTER__ probe.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHjiPBayDu7hLZyhcQK3tt
The entry asked setup-clang for version 19 and then compiled with
clang-20, which only worked because the runner image already ships it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHjiPBayDu7hLZyhcQK3tt
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHjiPBayDu7hLZyhcQK3tt
@philipcraig philipcraig changed the title Pin clang-tidy to LLVM 22 and add an opt-in pre-commit hook Move CI static analysis and sanitizers to LLVM 22 and add an opt-in clang-tidy pre-commit hook Aug 27, 2026
@philipcraig
philipcraig marked this pull request as ready for review August 27, 2026 14:37
@philipcraig
philipcraig requested a review from jbcoe as a code owner August 27, 2026 14:37

@jbcoe jbcoe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. 😊

@philipcraig
philipcraig merged commit 24a72fe into main Aug 27, 2026
44 checks passed
@philipcraig
philipcraig deleted the clang-tidy-22-pin branch August 27, 2026 16:02
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.

2 participants