[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
Edwin Vane via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 5 08:09:47 PDT 2024
https://github.com/revane created https://github.com/llvm/llvm-project/pull/87792
Although the identifier-naming.cpp lit test expected macro arguments not to be renamed, the code seemed to already allow it. The code was simply not being exercised because a SourceManager argument wasn't being provided. With this change, renaming of macro arguments that expand to renamable decls is permitted.
>From 71fbcdee7ebe3f49f2c0205ac2059451afeeb54e Mon Sep 17 00:00:00 2001
From: Edwin Vane <revane at google.com>
Date: Fri, 5 Apr 2024 11:06:01 -0400
Subject: [PATCH] [clang-tidy] Allow renaming macro arguments
Although the identifier-naming.cpp lit test expected macro arguments not
to be renamed, the code seemed to already allow it. The code was simply
not being exercised because a SourceManager argument wasn't being
provided. With this change, renaming of macro arguments that expand to
renamable decls is permitted.
---
.../clang-tidy/utils/RenamerClangTidyCheck.cpp | 7 +++----
.../checkers/readability/identifier-naming.cpp | 14 +++++++++-----
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index da1433aa2d05d4..45036822cf7a61 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -31,13 +31,12 @@ struct DenseMapInfo<clang::tidy::RenamerClangTidyCheck::NamingCheckId> {
using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId;
static inline NamingCheckId getEmptyKey() {
- return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
- "EMPTY"};
+ return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(), "EMPTY"};
}
static inline NamingCheckId getTombstoneKey() {
return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
- "TOMBSTONE"};
+ "TOMBSTONE"};
}
static unsigned getHashValue(NamingCheckId Val) {
@@ -473,7 +472,7 @@ void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
}
Failure.Info = std::move(Info);
- addUsage(Decl, Range);
+ addUsage(Decl, Range, &SourceMgr);
}
void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index d2e89a7c9855c9..289e493e04009b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -108,10 +108,12 @@ USER_NS::object g_s2;
// NO warnings or fixes expected as USER_NS and object are declared in a header file
SYSTEM_MACRO(var1);
-// NO warnings or fixes expected as var1 is from macro expansion
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'var1' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}SYSTEM_MACRO(g_var1);
USER_MACRO(var2);
-// NO warnings or fixes expected as var2 is declared in a macro expansion
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'var2' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}USER_MACRO(g_var2);
#define BLA int FOO_bar
BLA;
@@ -602,9 +604,11 @@ static void static_Function() {
// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
void MY_TEST_Macro(function) {}
-// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
-}
-}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global function 'function' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(Function) {}
+
+} // namespace InlineNamespace
+} // namespace FOO_NS
template <typename t_t> struct a {
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a'
More information about the cfe-commits
mailing list