Skip to content

ENH: Rework the clang-tidy configuration for C11 - #97

Merged
hjmjohnson merged 1 commit into
masterfrom
pr/clang-tidy-c11-config
Nov 14, 2026
Merged

hjmjohnson merged 1 commit into
masterfrom
pr/clang-tidy-c11-config

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #32, reverted from master on 2026-09-24 so it can be
reviewed before merging. Content is unchanged from the original.

Base: master. Independent: nothing has to land before it.

Commits
  • ENH: Rework the clang-tidy configuration for C11

Ordering for all the re-submitted work is tracked in #84.

@hjmjohnson
hjmjohnson marked this pull request as ready for review September 24, 2026 12:17
The .clang-tidy file has been in the tree since 2025 but nothing has ever
run it, and it shows: two of its entries name clang-analyzer checks that
upstream renamed some releases ago, so --verify-config warned about them.
Run over the whole tree it produced 1697 findings, of which the great
majority came from three style checks.  At that ratio nobody reads the
output.

Retuned for what this project actually is: C11, with a shipped ABI.
Measured with clang-tidy 22.1.8, USE_FSL_CODE=ON and USE_CIFTI_CODE=ON,
it now gives 331 findings across 15 checks, every one a defect class:

  170  bugprone-macro-parentheses
   44  bugprone-unchecked-string-to-number-conversion
   25  bugprone-multi-level-implicit-pointer-conversion
   19  readability-use-concise-preprocessor-directives
   16  bugprone-switch-missing-default-case
   13  readability-redundant-casting
    5  bugprone-suspicious-string-compare
    4  bugprone-suspicious-realloc-usage
    3  readability-redundant-control-flow
    2  readability-suspicious-call-argument
    2  bugprone-misplaced-widening-cast
    1  each: readability-implicit-bool-conversion,
         readability-function-size, misc-redundant-expression,
         bugprone-float-loop-counter

bugprone-macro-parentheses is re-enabled.  It had been switched off, but
it is the check that catches the real precedence bugs in the NT_DT_*,
QSTR and NT_FILL macro families.

misc-use-internal-linkage is switched off permanently, with the reason
recorded in the file.  It flags 29 functions, 13 of which are symbols
currently exported by libniftiio, libfslio and libcifti.  Applying its
fix-it would delete them from the shared libraries.  That it looks like a
tidy-up is exactly what makes it dangerous, so the file says so next to
the check rather than leaving the next person to rediscover it.

Every disabled check carries its finding count and the reason, so the
list can be re-argued from evidence instead of taste.

(cherry picked from commit 159d11d)
@hjmjohnson
hjmjohnson force-pushed the pr/clang-tidy-c11-config branch from 1d60872 to 9d423db Compare October 6, 2026 14:35

@gdevenyi gdevenyi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review by Google Carbon

Verdict: Approve (with non-blocking caveats for future clang-tidy CI wiring)

This is a thoughtful, well-documented C11 rework of .clang-tidy — explicitly calling out ABI-hazardous checks (misc-use-internal-linkage, readability-non-const-parameter) and re-enabling bugprone-macro-parentheses (paired with PR #122) is great hygiene. Since no workflow currently invokes clang-tidy as a gating check, this is safe to merge now.

Left three non-blocking inline notes to keep in mind when wiring clang-tidy into CI or landing #90/#89:

  1. Three negative check entries (-misc-use-internal-linkage, -readability-math-missing-parentheses, -readability-avoid-nested-conditional-operator) require LLVM >= 19 if clang-tidy --verify-config is used (Ubuntu 24.04's default clang-tidy package is LLVM 18).
  2. cmake invocation in the header comment omits -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON -DFSLSTYLE=ON; under -DFSLSTYLE=ON (-DPIGZ), doPigz's popen(command, "w") trips android-cloexec-popen and cert-env33-c (android-* as a whole isn't really applicable to a portable ISO C11 library).
  3. Updating the example symbol names in the misc-use-internal-linkage comment (FslFileType and fsl_fileexists are made static in #90/#89!).

Comment thread .clang-tidy
# run-clang-tidy -p build -j "$(nproc)" -quiet
#
Checks: '-*,
android-*,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Google Carbon] Non-blocking note: when configuring with -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON -DFSLSTYLE=ON (worth mentioning in the cmake -B build example on line 12!), doPigz (PIGZ) calls popen(command, "w"), which triggers android-cloexec-popen (demanding non-standard glibc/Bionic "we" mode in an ISO C11 build) and cert-env33-c. Dropping android-* altogether is likely cleaner for a cross-platform C11 library than disabling android-cloexec-* checks one by one.

Comment thread .clang-tidy
-misc-confusable-identifiers,
-misc-include-cleaner,
-misc-no-recursion,
-misc-use-internal-linkage,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Google Carbon] Heads-up for future CI setup: -misc-use-internal-linkage (here), -readability-avoid-nested-conditional-operator (line 54), and -readability-math-missing-parentheses (line 62) were introduced in LLVM 19. Regular clang-tidy runs ignore unknown negative patterns, but clang-tidy --verify-config will exit non-zero on Ubuntu 24.04's default clang-tidy-18 (18.1.3), so pin clang-tidy-19+ if --verify-config is added to CI. (Also, lines 54–55 aren't listed in the # Turned off as noise rationale block below.)

Comment thread .clang-tidy
# misc-use-internal-linkage Wants `static` on every function without a
# visible external use. It flags 29 distinct functions here, and 13 of
# them are symbols currently exported by libniftiio, libfslio or
# libcifti -- FslFileType, FslGetHdrImgNames, fsl_fileexists,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Google Carbon] Minor comment sync nit with PRs #90 and #89: both #90 and #89 actually mark FslFileType and fsl_fileexists static (removing them from exported_symbols_linux.txt) while keeping FslGetHdrImgNames, nifti_fileexists, etc. exported. Updating the example names here avoids contradicting #90/#89.

@hjmjohnson
hjmjohnson merged commit d8a0eb2 into master Nov 14, 2026
4 checks passed
@hjmjohnson
hjmjohnson deleted the pr/clang-tidy-c11-config branch November 14, 2026 14:29
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.

3 participants