From 3bdb551225bd4a663af39c66fdd1f27b12b7d90a Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 1/8] Silence output on check for GNU parallel binary --- etc/run-clang-tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/run-clang-tidy.sh b/etc/run-clang-tidy.sh index 47efcd3900..88632651bb 100755 --- a/etc/run-clang-tidy.sh +++ b/etc/run-clang-tidy.sh @@ -11,7 +11,7 @@ if [[ "${distro_id:?}" != rhel* ]]; then exit 1 fi -if ! command -V parallel >/dev/null; then +if ! command -v parallel >/dev/null; then sudo yum install -q -y parallel fi From 6c28bb8de2385ae833d3adf58260ca8111bd7a7b Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 2/8] CXX-2338 migrate clang-tidy to rhel9-latest distro --- .evergreen/config_generator/components/clang_tidy.py | 6 +++--- .evergreen/config_generator/etc/distros.py | 2 +- .evergreen/generated_configs/tasks.yml | 4 ++-- etc/run-clang-tidy.sh | 4 +--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.evergreen/config_generator/components/clang_tidy.py b/.evergreen/config_generator/components/clang_tidy.py index ca04269503..9f0cb0764f 100644 --- a/.evergreen/config_generator/components/clang_tidy.py +++ b/.evergreen/config_generator/components/clang_tidy.py @@ -6,7 +6,7 @@ from config_generator.components.funcs.install_c_driver import InstallCDriver from config_generator.components.funcs.setup import Setup -from config_generator.etc.distros import compiler_to_vars, find_small_distro +from config_generator.etc.distros import compiler_to_vars, find_large_distro from config_generator.etc.function import Function from config_generator.etc.utils import bash_exec @@ -40,8 +40,8 @@ def functions(): def tasks(): - distro_name = 'rhel80' - distro = find_small_distro(distro_name) + distro_name = 'rhel9-latest' + distro = find_large_distro(distro_name) return [ EvgTask( diff --git a/.evergreen/config_generator/etc/distros.py b/.evergreen/config_generator/etc/distros.py index 2fbafc5987..3a6e64b8f8 100644 --- a/.evergreen/config_generator/etc/distros.py +++ b/.evergreen/config_generator/etc/distros.py @@ -63,6 +63,7 @@ def ls_distro(name, **kwargs): ] RHEL_DISTROS = [ + *ls_distro(name='rhel9-latest', os='rhel', os_type='linux', os_ver='9'), *ls_distro(name='rhel7.9', os='rhel', os_type='linux', os_ver='7.9'), *ls_distro(name='rhel80', os='rhel', os_type='linux', os_ver='8.0'), *ls_distro(name='rhel84', os='rhel', os_type='linux', os_ver='8.4'), @@ -72,7 +73,6 @@ def ls_distro(name, **kwargs): *ls_distro(name='rhel93', os='rhel', os_type='linux', os_ver='9.3'), *ls_distro(name='rhel94', os='rhel', os_type='linux', os_ver='9.4'), *ls_distro(name='rhel95', os='rhel', os_type='linux', os_ver='9.5'), - *ls_distro(name='rhel92', os='rhel', os_type='linux', os_ver='9.0'), ] RHEL_ARM64_DISTROS = [ diff --git a/.evergreen/generated_configs/tasks.yml b/.evergreen/generated_configs/tasks.yml index 1c7b38a3b6..e57460c152 100644 --- a/.evergreen/generated_configs/tasks.yml +++ b/.evergreen/generated_configs/tasks.yml @@ -151,8 +151,8 @@ tasks: - func: benchmarks-compile - func: benchmarks-run - name: clang-tidy - run_on: rhel80-small - tags: [clang-tidy, rhel80] + run_on: rhel9-latest-large + tags: [clang-tidy, rhel9-latest] commands: - func: setup - func: install_c_driver diff --git a/etc/run-clang-tidy.sh b/etc/run-clang-tidy.sh index 88632651bb..bc523806ae 100755 --- a/etc/run-clang-tidy.sh +++ b/etc/run-clang-tidy.sh @@ -11,9 +11,7 @@ if [[ "${distro_id:?}" != rhel* ]]; then exit 1 fi -if ! command -v parallel >/dev/null; then - sudo yum install -q -y parallel -fi +command -V parallel >/dev/null # shellcheck source=/dev/null . .evergreen/scripts/install-build-tools.sh From 2f728ecbdd888d3d01bd803dcc7074efd2b7dde3 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 3/8] Filter clang-tidy task to library sources only --- etc/run-clang-tidy.sh | 44 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/etc/run-clang-tidy.sh b/etc/run-clang-tidy.sh index bc523806ae..f0e689d10c 100755 --- a/etc/run-clang-tidy.sh +++ b/etc/run-clang-tidy.sh @@ -19,7 +19,8 @@ install_build_tools export CMAKE_GENERATOR="Ninja" uv tool install -q clang-tidy -clang-tidy --version +version="$(clang-tidy --version | perl -lne 'print $1 if m|LLVM version (\d+\.\d+\.\d+)|')" +echo "clang-tidy version: ${version:?}" # Use ccache if available. if [[ -f "../mongoc/.evergreen/scripts/find-ccache.sh" ]]; then @@ -36,41 +37,14 @@ cmake_config_flags=( ) # Generate the compilation database file. -cmake -S . -B build "${cmake_config_flags[@]}" +cmake "${cmake_config_flags[@]}" -B build -# Some files (i.e. headers) may need to be generated during the build step. -cmake --build build +mapfile -t sources < <(find src -type f \( -name *.cc -o -name *.cpp \) | perl -lne 'print if m$.*/(?:bsoncxx|mongocxx)/lib/.*$') -# -# Each check has a name and the checks to run can be chosen using the -checks= option, which specifies a comma-separated -# list of positive and negative (prefixed with -) globs. For example: -# -# $ clang-tidy test.cpp -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* -# -# will disable all default checks (-*) and enable all clang-analyzer-* checks except for clang-analyzer-cplusplus* ones. -# -# The -list-checks option lists all the enabled checks. When used without -checks=, it shows checks enabled by default. -# Use -checks=* to see all available checks or with any other value of -checks= to see which checks are enabled by this -# value. -# -# see https://clang.llvm.org/extra/clang-tidy -# - -echo "Running clang-tidy with configuration:" -clang-tidy -p=build -dump-config - -find_args=( - -type f - \( -name *.hh -o -name *.hpp -o -name *.cpp \) # All sources including headers. - -not -path "*/third_party/*" # Excluding third party headers. - -not -path "*/config/*.hpp" # Excluding config headers. - -not -path "*bsoncxx/v_noabi/bsoncxx/enums/*.hpp" # Excluding X macro headers. +clang_tidy_flags=( + --quiet + -p build + --header-filter '.*/(?:bsoncxx|mongocxx)/(?:include|lib)/.*' ) -echo "Scanning the following files:" -find src "${find_args[@]}" - -# TODO: update clang-tidy config and address warnings. -{ - find src "${find_args[@]}" | parallel clang-tidy --quiet -p=build {} 2>/dev/null -} || true +printf "%s\n" "${sources[@]}" | parallel -q "${parallel_flags[@]}" clang-tidy "${clang_tidy_flags[@]:?}" {} 2>/dev/null From e0f3d40c030d82cded2c45ffa5976cf3cf3392cc Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 4/8] clang-tidy: dump config for 21.1.1 --- .clang-tidy | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index fcff55586e..84b103c20c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,2 +1,120 @@ -Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,cert-*,cppcoreguidelines-*,clang-analyzer-*' +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*,-*,cert-*,cppcoreguidelines-*,clang-analyzer-*' WarningsAsErrors: '' +HeaderFileExtensions: + - '' + - h + - hh + - hpp + - hxx +ImplementationFileExtensions: + - c + - cc + - cpp + - cxx +HeaderFilterRegex: '' +ExcludeHeaderFilterRegex: '' +FormatStyle: none +User: ec2-user +CheckOptions: + cert-arr39-c.WarnOnOffsetDividedBySizeOf: 'true' + cert-arr39-c.WarnOnSizeOfCompareToConstant: 'false' + cert-arr39-c.WarnOnSizeOfConstant: 'false' + cert-arr39-c.WarnOnSizeOfInLoopTermination: 'true' + cert-arr39-c.WarnOnSizeOfIntegerExpression: 'false' + cert-arr39-c.WarnOnSizeOfPointer: 'false' + cert-arr39-c.WarnOnSizeOfPointerToAggregate: 'false' + cert-arr39-c.WarnOnSizeOfThis: 'false' + cert-ctr56-cpp.IgnoreInheritedVirtualFunctions: 'false' + cert-dcl16-c.IgnoreMacros: 'true' + cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU' + cert-dcl37-c.AggressiveDependentMemberLookup: 'false' + cert-dcl37-c.AllowedIdentifiers: '' + cert-dcl37-c.Invert: 'false' + cert-dcl51-cpp.AggressiveDependentMemberLookup: 'false' + cert-dcl51-cpp.AllowedIdentifiers: '' + cert-dcl51-cpp.Invert: 'false' + cert-err09-cpp.CheckThrowTemporaries: 'true' + cert-err09-cpp.MaxSize: '18446744073709551615' + cert-err09-cpp.WarnOnLargeObjects: 'false' + cert-err33-c.AllowCastToVoid: 'true' + cert-err33-c.CheckedFunctions: '^::aligned_alloc$;^::asctime_s$;^::at_quick_exit$;^::atexit$;^::bsearch$;^::bsearch_s$;^::btowc$;^::c16rtomb$;^::c32rtomb$;^::calloc$;^::clock$;^::cnd_broadcast$;^::cnd_init$;^::cnd_signal$;^::cnd_timedwait$;^::cnd_wait$;^::ctime_s$;^::fclose$;^::fflush$;^::fgetc$;^::fgetpos$;^::fgets$;^::fgetwc$;^::fopen$;^::fopen_s$;^::fprintf$;^::fprintf_s$;^::fputc$;^::fputs$;^::fputwc$;^::fputws$;^::fread$;^::freopen$;^::freopen_s$;^::fscanf$;^::fscanf_s$;^::fseek$;^::fsetpos$;^::ftell$;^::fwprintf$;^::fwprintf_s$;^::fwrite$;^::fwscanf$;^::fwscanf_s$;^::getc$;^::getchar$;^::getenv$;^::getenv_s$;^::gets_s$;^::getwc$;^::getwchar$;^::gmtime$;^::gmtime_s$;^::localtime$;^::localtime_s$;^::malloc$;^::mbrtoc16$;^::mbrtoc32$;^::mbsrtowcs$;^::mbsrtowcs_s$;^::mbstowcs$;^::mbstowcs_s$;^::memchr$;^::mktime$;^::mtx_init$;^::mtx_lock$;^::mtx_timedlock$;^::mtx_trylock$;^::mtx_unlock$;^::printf_s$;^::putc$;^::putwc$;^::raise$;^::realloc$;^::remove$;^::rename$;^::scanf$;^::scanf_s$;^::setlocale$;^::setvbuf$;^::signal$;^::snprintf$;^::snprintf_s$;^::sprintf$;^::sprintf_s$;^::sscanf$;^::sscanf_s$;^::strchr$;^::strerror_s$;^::strftime$;^::strpbrk$;^::strrchr$;^::strstr$;^::strtod$;^::strtof$;^::strtoimax$;^::strtok$;^::strtok_s$;^::strtol$;^::strtold$;^::strtoll$;^::strtoul$;^::strtoull$;^::strtoumax$;^::strxfrm$;^::swprintf$;^::swprintf_s$;^::swscanf$;^::swscanf_s$;^::thrd_create$;^::thrd_detach$;^::thrd_join$;^::thrd_sleep$;^::time$;^::timespec_get$;^::tmpfile$;^::tmpfile_s$;^::tmpnam$;^::tmpnam_s$;^::tss_create$;^::tss_get$;^::tss_set$;^::ungetc$;^::ungetwc$;^::vfprintf$;^::vfprintf_s$;^::vfscanf$;^::vfscanf_s$;^::vfwprintf$;^::vfwprintf_s$;^::vfwscanf$;^::vfwscanf_s$;^::vprintf_s$;^::vscanf$;^::vscanf_s$;^::vsnprintf$;^::vsnprintf_s$;^::vsprintf$;^::vsprintf_s$;^::vsscanf$;^::vsscanf_s$;^::vswprintf$;^::vswprintf_s$;^::vswscanf$;^::vswscanf_s$;^::vwprintf_s$;^::vwscanf$;^::vwscanf_s$;^::wcrtomb$;^::wcschr$;^::wcsftime$;^::wcspbrk$;^::wcsrchr$;^::wcsrtombs$;^::wcsrtombs_s$;^::wcsstr$;^::wcstod$;^::wcstof$;^::wcstoimax$;^::wcstok$;^::wcstok_s$;^::wcstol$;^::wcstold$;^::wcstoll$;^::wcstombs$;^::wcstombs_s$;^::wcstoul$;^::wcstoull$;^::wcstoumax$;^::wcsxfrm$;^::wctob$;^::wctrans$;^::wctype$;^::wmemchr$;^::wprintf_s$;^::wscanf$;^::wscanf_s$' + cert-err33-c.CheckedReturnTypes: '^::std::error_code$;^::std::error_condition$;^::std::errc$;^::std::expected$;^::boost::system::error_code$' + cert-err61-cpp.CheckThrowTemporaries: 'true' + cert-err61-cpp.MaxSize: '18446744073709551615' + cert-err61-cpp.WarnOnLargeObjects: 'false' + cert-int09-c.AllowExplicitSequentialInitialValues: 'true' + cert-int09-c.AllowExplicitZeroFirstInitialValue: 'true' + cert-msc24-c.CustomFunctions: '' + cert-msc24-c.ReportDefaultFunctions: 'true' + cert-msc24-c.ReportMoreUnsafeFunctions: 'true' + cert-msc32-c.DisallowedSeedTypes: 'time_t,std::time_t' + cert-msc33-c.CustomFunctions: '' + cert-msc33-c.ReportDefaultFunctions: 'true' + cert-msc33-c.ReportMoreUnsafeFunctions: 'true' + cert-msc51-cpp.DisallowedSeedTypes: 'time_t,std::time_t' + cert-msc54-cpp.AsyncSafeFunctionSet: POSIX + cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false' + cert-oop57-cpp.MemCmpNames: '' + cert-oop57-cpp.MemCpyNames: '' + cert-oop57-cpp.MemSetNames: '' + cert-sig30-c.AsyncSafeFunctionSet: POSIX + cert-str34-c.CharTypdefsToIgnore: '' + cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false' + cppcoreguidelines-avoid-c-arrays.AllowStringArrays: 'false' + cppcoreguidelines-avoid-do-while.IgnoreMacros: 'false' + cppcoreguidelines-avoid-goto.IgnoreMacros: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths: 'true' + cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoreTypeAliases: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoreUserDefinedLiterals: 'false' + cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues: '1.0;100.0;' + cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues: '1;2;3;4;' + cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage: 'false' + cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal: 'false' + cppcoreguidelines-explicit-virtual-functions.FinalSpelling: final + cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors: 'false' + cppcoreguidelines-explicit-virtual-functions.IgnoreTemplateInstantiations: 'false' + cppcoreguidelines-explicit-virtual-functions.OverrideSpelling: override + cppcoreguidelines-init-variables.IncludeStyle: llvm + cppcoreguidelines-init-variables.MathHeader: '' + cppcoreguidelines-macro-usage.AllowedRegexp: '^DEBUG_*' + cppcoreguidelines-macro-usage.CheckCapsOnly: 'false' + cppcoreguidelines-macro-usage.IgnoreCommandLineMacros: 'true' + cppcoreguidelines-missing-std-forward.ForwardFunction: '::std::forward' + cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes: '' + cppcoreguidelines-narrowing-conversions.PedanticMode: 'false' + cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth: 'true' + cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion: 'true' + cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true' + cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion: 'true' + cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation: 'false' + cppcoreguidelines-no-malloc.Allocations: '::malloc;::calloc' + cppcoreguidelines-no-malloc.Deallocations: '::free' + cppcoreguidelines-no-malloc.Reallocations: '::realloc' + cppcoreguidelines-no-suspend-with-lock.LockGuards: '::std::unique_lock;::std::scoped_lock;::std::shared_lock;::std::lock_guard' + cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true' + cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'false' + cppcoreguidelines-owning-memory.LegacyResourceConsumers: '::free;::realloc;::freopen;::fclose' + cppcoreguidelines-owning-memory.LegacyResourceProducers: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile' + cppcoreguidelines-pro-bounds-constant-array-index.GslHeader: '' + cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle: llvm + cppcoreguidelines-pro-type-const-cast.StrictMode: 'false' + cppcoreguidelines-pro-type-member-init.IgnoreArrays: 'false' + cppcoreguidelines-pro-type-member-init.UseAssignment: 'false' + cppcoreguidelines-pro-type-static-cast-downcast.StrictMode: 'true' + cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: 'false' + cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: 'false' + cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: 'false' + cppcoreguidelines-rvalue-reference-param-not-moved.MoveFunction: '::std::move' + cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: 'false' + cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: 'false' + cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'false' + cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: 'false' + cppcoreguidelines-special-member-functions.IgnoreMacros: 'true' + cppcoreguidelines-use-default-member-init.IgnoreMacros: 'true' + cppcoreguidelines-use-default-member-init.UseAssignment: 'false' + cppcoreguidelines-use-enum-class.IgnoreUnscopedEnumsInClasses: 'false' +SystemHeaders: false +... From 35e38646dae5b802b01db4b37a3e3cf0d338ff3a Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 5/8] clang-tidy: set User to empty string --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 84b103c20c..14fdec2e3a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,7 @@ ImplementationFileExtensions: HeaderFilterRegex: '' ExcludeHeaderFilterRegex: '' FormatStyle: none -User: ec2-user +User: '' CheckOptions: cert-arr39-c.WarnOnOffsetDividedBySizeOf: 'true' cert-arr39-c.WarnOnSizeOfCompareToConstant: 'false' From 1dbcb5ba0f8b2e9648c047c856fd28bf9eac93fb Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 6/8] clang-tidy: exclude non-includable headers --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 14fdec2e3a..1d2b29388f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -13,7 +13,7 @@ ImplementationFileExtensions: - cpp - cxx HeaderFilterRegex: '' -ExcludeHeaderFilterRegex: '' +ExcludeHeaderFilterRegex: '(?:.*/bsoncxx/enums/.*|.*/(?:prelude|postlude)\.hpp$)' FormatStyle: none User: '' CheckOptions: From fc3b988fd23bd65c2dda64f212f7c152f53c448c Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 7/8] clang-tidy: convert checks string into list --- .clang-tidy | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 1d2b29388f..c8954c4617 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,13 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*,-*,cert-*,cppcoreguidelines-*,clang-analyzer-*' +Checks: + - clang-diagnostic-* + - clang-analyzer-* + - clang-diagnostic-* + - clang-analyzer-* + - -* + - cert-* + - cppcoreguidelines-* + - clang-analyzer-*' WarningsAsErrors: '' HeaderFileExtensions: - '' From 4e8c3bc8e5923c6a3ff21b82de807be5a3e51bd1 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 12 Nov 2025 09:14:05 -0600 Subject: [PATCH 8/8] clang-tidy: remove redundant checks in list --- .clang-tidy | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c8954c4617..776cc38656 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,9 +1,5 @@ --- Checks: - - clang-diagnostic-* - - clang-analyzer-* - - clang-diagnostic-* - - clang-analyzer-* - -* - cert-* - cppcoreguidelines-*