Skip to content

Add clang-tidy#8073

Open
Jacobfaib wants to merge 1 commit intoNVIDIA:mainfrom
Jacobfaib:jacobf/2026-03-17/clang-tidy
Open

Add clang-tidy#8073
Jacobfaib wants to merge 1 commit intoNVIDIA:mainfrom
Jacobfaib:jacobf/2026-03-17/clang-tidy

Conversation

@Jacobfaib
Copy link
Contributor

@Jacobfaib Jacobfaib commented Mar 17, 2026

Description

Add a clang-tidy pass that runs over every created executable in CCCL. Run it via

$ cmake --build build --target tidy
[0/212] clang-tidy build/all-dev-debug/thrust/testing/thrust.cpp.cpp/address_stability.cu.cpp
...

The tidy target is only created for top-level builds. Crucially, the tidy target is lazy; if the host system has no clang-tidy, then an error is only emitted when you invoke --target tidy, not at configure-time. This allows seamless "opt-in" behavior.

Example of current errors generated:
clang_tidy_errors_sample.log

Please note that many errors (notably bugprone-reserved-identifier inside libcu++) can be locally silenced by a directory-local .clang-tidy, so please ignore them until the local .clang-tidy has been added.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@Jacobfaib Jacobfaib self-assigned this Mar 17, 2026
@github-project-automation github-project-automation bot moved this to Todo in CCCL Mar 17, 2026
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 17, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Progress in CCCL Mar 17, 2026
@Jacobfaib
Copy link
Contributor Author

Some follow-ups for (eventual) reviewers: readability-identifier-naming allows automating the naming scheme with clang-tidy. Each subproject follows roughly the same style guide, but not always (cudax/ for example is a bit all over the place).

I propose these checks are enabled in a follow-up, as it will be adding to an already massive diff in this PR.

@Jacobfaib
Copy link
Contributor Author

Also which CI job is best suited for this? I notice there isn't really a unified "lint" job (other than pre-commit). clang-tidy works only on what it sees. We don't need to run it for every combination of compiler and OS that CCCL supports, but it should run in a configuration with as many optional features enabled as possible.

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

I am looking forward to clang-tidy, but we need to be really careful that we do not emit incorrect warnings.

We do have standard library components and need to account for that

@Jacobfaib
Copy link
Contributor Author

We do have standard library components and need to account for that

The way this will be handled will be a separate .clang-tidy under libcudacxx/, I just haven't put it in yet. When emitting diagnostics, clang-tidy will find the closest .clang-tidy to the file that contains the code, so we can have different configurations for each package. For example, we will need to disable bugprone-reserved-identifier for it (actually, bugprone-reserved-identifier has an Invert option that flags names that are not prefixed with __).

@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch from 0e093d5 to d14b439 Compare March 18, 2026 16:41
@bernhardmgruber
Copy link
Contributor

We do have standard library components and need to account for that

The way this will be handled will be a separate .clang-tidy under libcudacxx/, I just haven't put it in yet. When emitting diagnostics, clang-tidy will find the closest .clang-tidy to the file that contains the code, so we can have different configurations for each package. For example, we will need to disable bugprone-reserved-identifier for it (actually, bugprone-reserved-identifier has an Invert option that flags names that are not prefixed with __).

CUB and Thrust also use __ prefixes on some internal functions. At least I started using that. But a lot of other code uses a detail namespace. So we can actually run neither check before harmonizing to a single rule for internal functions :D

@jrhemstad
Copy link
Collaborator

Also which CI job is best suited for this? I notice there isn't really a unified "lint" job (other than pre-commit). clang-tidy works only on what it sees. We don't need to run it for every combination of compiler and OS that CCCL supports, but it should run in a configuration with as many optional features enabled as possible.

@alliepiper can you point @Jacobfaib in the right direction here?

@Jacobfaib
Copy link
Contributor Author

CUB and Thrust also use __ prefixes on some internal functions. At least I started using that. But a lot of other code uses a detail namespace. So we can actually run neither check before harmonizing to a single rule for internal functions :D

So I misread clang-tidy when it said that it would match the closest .clang-tidy to a particular file. It matches the closest .clang-tidy to the source file, not the file that was included by the source file. So cuda/std/foo.h included by cccl/foo/bar/baz.cpp will never "match" against cccl/libcudacxx/.clang-tidy because clang-tidy finds cccl/.clang-tidy.

To fix this, I think we just disable bugprone-reserved-identifier entirely for now and then I can add in a custom check that looks up the .clang-tidy based on the location of the symbol (or just hard-code that anything in ::cuda::std is allowed __).

CUB and Thrust also use __ prefixes on some internal functions.

My 2 cents would be that only ::cuda::std is allowed the __. As low-level and special to NVIDIA as CUB and thrust are, they aren't really a "standard library" so detail namespace is appropriate. But will defer to others on this decision.

@miscco
Copy link
Contributor

miscco commented Mar 23, 2026

My 2 cents would be that only ::cuda::std is allowed the __. As low-level and special to NVIDIA as CUB and thrust are, they aren't really a "standard library" so detail namespace is appropriate. But will defer to others on this decision.

I believe that is correct, albeit we are starting to use effectively all of CUB in the PSTL CUDA backend, so technically ...

@alliepiper
Copy link
Contributor

Also which CI job is best suited for this?

@Jacobfaib We should put this in a new CI job. We'll need that level of control. As a first step, I propose adding new ci/tidy_.sh scripts that use the existing common-ci-job infra to compile some new CMake presets, and some "tidy" jobs in ci/matrix.yaml that mirror the "build" job configs.

Take a look through the comments and docs in:

  • ci/matrix.yaml (job defs, script locations and interfaces). See how the "build" job is setup (ignore the "build-lid0" etc variants, you won't need those), and use that as a template for defining a "tidy" job.
  • CMakePresets.json is where you'll configure the tidy job configure, build, and (if needed?) ctest presets for the per-project, per-dialect builds.
  • ci/build_libcudacxx.sh is the most straightforward build script to use as a template. You shouldn't need to mirror the complexity of say, build_cub.sh to get this working. We can look into splitting things up later if the runtime is bad enough.

Important: Use the override matrix in the ci/matrix.yaml file to test your new jobs without triggering a full 500+ job CI pipeline execution while iterating.


So:

  1. New "tidy" job type def + pull_request/nightly/weekly jobs in ci/matrix.yaml (test with override matrix)
  2. New config + build presets in CMakePresets.json
  3. New ci/tidy_<project>.sh scripts per-project, following the build_libcudacxx.sh script as a template.

@Jacobfaib
Copy link
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch from 04fb404 to fe4cb0a Compare March 23, 2026 15:56
@Jacobfaib
Copy link
Contributor Author

/ok to test

3 similar comments
@Jacobfaib
Copy link
Contributor Author

/ok to test

@Jacobfaib
Copy link
Contributor Author

/ok to test

@Jacobfaib
Copy link
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib
Copy link
Contributor Author

/ok to test

2 similar comments
@Jacobfaib
Copy link
Contributor Author

/ok to test

@Jacobfaib
Copy link
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib
Copy link
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch 2 times, most recently from 35ec44c to 253f419 Compare March 23, 2026 18:06
@Jacobfaib
Copy link
Contributor Author

Jacobfaib commented Mar 23, 2026

Per offline discussion, the consensus was that trying to go whole-hog with all checks enabled and fixes applied would be a nightmare to review/downright impossible.

Instead, we should merge a minimal passing version of this PR in ASAP to get the clang-tidy machinery itself into CI and the build system, then slowly ratchet up the enabled checks until we have everything enabled/fixed.

To whit, this PR now enables only a single check, performance-implicit-conversion-in-loop (https://github.com/NVIDIA/cccl/pull/8073/changes#diff-0534891fbc8b89b4c521057e7e8dff70d3cbeb822cc9991a3abad77848c289f8R23) (which CCCL seems to be passing).

@Jacobfaib Jacobfaib marked this pull request as ready for review March 23, 2026 18:09
@Jacobfaib Jacobfaib requested review from a team as code owners March 23, 2026 18:09
@cccl-authenticator-app cccl-authenticator-app bot moved this from In Progress to In Review in CCCL Mar 23, 2026
@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch from 253f419 to 5f10901 Compare March 23, 2026 18:20
ci/matrix.yaml Outdated
# Used by the clang-tidy jobs. Does not really mean "all", because it does not name all
# projects, this is more "project-less" because clang-tidy will by default be invoked
# over all configured sub-projects.
all:
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to split this up into per-project scripts from this list to work with our change-detection logic that determines which areas of the CCCL need to be built and tested.

@github-actions

This comment has been minimized.

Copy link
Contributor

@fbusato fbusato left a comment

Choose a reason for hiding this comment

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

totally fine if we disable the checks to add them in further PRs.
I strongly suggest further review of the cmake part because it touches several places.

@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch from 2d8879a to 9a2a310 Compare March 24, 2026 22:05
@Jacobfaib Jacobfaib force-pushed the jacobf/2026-03-17/clang-tidy branch from 9a2a310 to 2b92a66 Compare March 24, 2026 22:10
@github-actions
Copy link
Contributor

😬 CI Workflow Results

🟥 Finished in 3h 46m: Pass: 99%/446 | Total: 14d 22h | Max: 3h 46m | Hits: 66%/511977

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

6 participants