https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/147793
Added `.clang-tidy` config as discussed in [RFC](https://discourse.llvm.org/t/rfc-create-hardened-clang-tidy-config-for-clang-tidy-directory/87247). Added `bugprone` checks that didn't create many warnings. Fixed minor warnings to make `/clang-tidy` directory complaint with `clang-tidy-20`. Disabled checks will be enabled in future PRs after fixing their warnings. >From 86802f21ec42dd66de106d08039103907f73c0d5 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Wed, 9 Jul 2025 20:38:16 +0300 Subject: [PATCH] [clang-tidy] add .clang-tidy config for clang-tidy project --- clang-tools-extra/clang-tidy/.clang-tidy | 11 +++++++++++ .../bugprone/CrtpConstructorAccessibilityCheck.cpp | 7 ++----- .../clang-tidy/bugprone/SizeofExpressionCheck.cpp | 10 +++++----- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 clang-tools-extra/clang-tidy/.clang-tidy diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy new file mode 100644 index 0000000000000..45d1929b6b742 --- /dev/null +++ b/clang-tools-extra/clang-tidy/.clang-tidy @@ -0,0 +1,11 @@ +InheritParentConfig: true +Checks: [ + bugprone-* + -bugprone-assignment-in-if-condition, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + -bugprone-narrowing-conversions, + -bugprone-suspicious-stringview-data-usage, + -bugprone-unchecked-optional-access, + -bugprone-unused-return-value, +] diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp index 28e8fe002d575..6565fa3f7c85b 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp @@ -129,13 +129,10 @@ void CrtpConstructorAccessibilityCheck::check( << HintFriend; } - auto WithFriendHintIfNeeded = - [&](const DiagnosticBuilder &Diag, - bool NeedsFriend) -> const DiagnosticBuilder & { + auto WithFriendHintIfNeeded = [&](const DiagnosticBuilder &Diag, + bool NeedsFriend) { if (NeedsFriend) Diag << HintFriend; - - return Diag; }; if (!CRTPDeclaration->hasUserDeclaredConstructor()) { diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index 88d2f2c388d07..88e048e65d4e8 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp @@ -370,16 +370,16 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) { << E->getSourceRange(); } else if (Result.Nodes.getNodeAs<Stmt>("loop-expr")) { auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type"); - if (const auto member = dyn_cast<MemberPointerType>(SizeofArgTy)) - SizeofArgTy = member->getPointeeType().getTypePtr(); + if (const auto *Member = dyn_cast<MemberPointerType>(SizeofArgTy)) + SizeofArgTy = Member->getPointeeType().getTypePtr(); const auto *SzOfExpr = Result.Nodes.getNodeAs<Expr>("sizeof-expr"); - if (const auto type = dyn_cast<ArrayType>(SizeofArgTy)) { + if (const auto *Type = dyn_cast<ArrayType>(SizeofArgTy)) { // check if the array element size is larger than one. If true, // the size of the array is higher than the number of elements - CharUnits sSize = Ctx.getTypeSizeInChars(type->getElementType()); - if (!sSize.isOne()) { + CharUnits SSize = Ctx.getTypeSizeInChars(Type->getElementType()); + if (!SSize.isOne()) { diag(SzOfExpr->getBeginLoc(), "suspicious usage of 'sizeof' in the loop") << SzOfExpr->getSourceRange(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits