-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang-tidy][NFC] add '.clang-tidy' config for clang-tidy project #147793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-tidy Author: Baranov Victor (vbvictor) ChangesAdded Disabled checks will be enabled in future PRs after fixing their warnings. Full diff: https://github.com/llvm/llvm-project/pull/147793.diff 3 Files Affected:
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();
|
@llvm/pr-subscribers-clang-tools-extra Author: Baranov Victor (vbvictor) ChangesAdded Disabled checks will be enabled in future PRs after fixing their warnings. Full diff: https://github.com/llvm/llvm-project/pull/147793.diff 3 Files Affected:
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();
|
Added all people that participated in RFC and regular clang-tidy reviewers to see this change. |
How about adding |
Yes, I will add more and more checks to config. Just started with
Noted, will check that. |
Yes, one go is straightforward. However, if preliminary code fixes will be necessary, they should go into separate pull request. |
86802f2
to
a0fd1b0
Compare
Results of running with config (disabled checks that doesn't align with our style)
report.html.txt (delete |
7dbf98f
to
4b061f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But please wait for other reviewers.
Will be good idea to similar Clang-Tidy configuration over other parts of LLVM code base. May be some check warnings will be easy to fix and enforce. I did such cleanups in past (by quite remote :-(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Added
.clang-tidy
config as discussed in RFC.Added
bugprone
,readability
,modernize
,performance
checks that didn't create many warnings.Fixed minor warnings to make
/clang-tidy
directory complaint withclang-tidy-20
.Disabled checks will be enabled in future PRs after fixing their warnings.