Repository navigation
ENH: Rework the clang-tidy configuration for C11 - #97
Conversation
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)
1d60872 to
9d423db
Compare
gdevenyi
left a comment
There was a problem hiding this comment.
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:
- Three negative check entries (
-misc-use-internal-linkage,-readability-math-missing-parentheses,-readability-avoid-nested-conditional-operator) require LLVM >= 19 ifclang-tidy --verify-configis used (Ubuntu 24.04's defaultclang-tidypackage is LLVM 18). cmakeinvocation in the header comment omits-DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON -DFSLSTYLE=ON; under-DFSLSTYLE=ON(-DPIGZ),doPigz'spopen(command, "w")tripsandroid-cloexec-popenandcert-env33-c(android-*as a whole isn't really applicable to a portable ISO C11 library).- Updating the example symbol names in the
misc-use-internal-linkagecomment (FslFileTypeandfsl_fileexistsare madestaticin#90/#89!).
| # run-clang-tidy -p build -j "$(nproc)" -quiet | ||
| # | ||
| Checks: '-*, | ||
| android-*, |
There was a problem hiding this comment.
[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.
| -misc-confusable-identifiers, | ||
| -misc-include-cleaner, | ||
| -misc-no-recursion, | ||
| -misc-use-internal-linkage, |
There was a problem hiding this comment.
[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.)
| # 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, |
There was a problem hiding this comment.
[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.
Re-submission of #32, reverted from
masteron 2026-09-24 so it can bereviewed before merging. Content is unchanged from the original.
Base:
master. Independent: nothing has to land before it.Commits
Ordering for all the re-submitted work is tracked in #84.