[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)
revane wrote: Does this PR address a bug I logged? I'm not sure why you've requested my input. https://github.com/llvm/llvm-project/pull/70801 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)
revane wrote: I haven't touched this code in 10 years. I don't think I'm a good candidate for providing a review. https://github.com/llvm/llvm-project/pull/70801 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Support renaming designated initializers (PR #86976)
https://github.com/revane created https://github.com/llvm/llvm-project/pull/86976 Until now, they were just ignored by RenamerClangTidyCheck. >From 85539210edf644259bb0dbb1d090e092709a1a1d Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:24:34 -0400 Subject: [PATCH] Support renaming designated initializers Until now, they were just ignored by RenamerClangTidyCheck. --- .../utils/RenamerClangTidyCheck.cpp | 19 +++ .../readability/identifier-naming.cpp | 8 2 files changed, 27 insertions(+) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index da1433aa2d05d4..e3409dfbb8f677 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -367,6 +367,25 @@ class RenamerClangTidyVisitor return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) { +for (const auto &Designator : Expr->designators()) { + if (!Designator.isFieldDesignator()) +continue; + auto *FieldDecl = Designator.getFieldDecl(); + if (!FieldDecl) +continue; + auto *II = FieldDecl->getIdentifier(); + if (!II) +continue; + SourceRange FixLocation{ + Designator.getFieldLoc(), + Designator.getFieldLoc().getLocWithOffset(II->getLength())}; + Check->addUsage(FieldDecl, FixLocation, SM); +} + +return true; + } + private: RenamerClangTidyCheck *Check; const SourceManager *SM; 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 84bf7764583e80..9c390e544c2abd 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 @@ -755,3 +755,11 @@ STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr) {} // CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t) {} #undef STATIC_MACRO } + +struct Some_struct { + int SomeMember; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for public member 'SomeMember' [readability-identifier-naming] +// CHECK-FIXES: {{^}} int some_member; +}; +Some_struct g_s{ .SomeMember = 1 }; +// CHECK-FIXES: {{^}}Some_struct g_s{ .some_member = 1 }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Support renaming designated initializers (PR #86976)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/86976 >From f8604d450fa3852d5c684bc8ada228a07ce6ccf5 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:24:34 -0400 Subject: [PATCH] Support renaming designated initializers Until now, they were just ignored by RenamerClangTidyCheck. --- .../clang-tidy/utils/RenamerClangTidyCheck.cpp | 18 ++ clang-tools-extra/docs/ReleaseNotes.rst| 3 ++- .../checkers/readability/identifier-naming.cpp | 10 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index da1433aa2d05d4..1edab9504b0ec0 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -367,6 +367,24 @@ class RenamerClangTidyVisitor return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) { +for (const auto &Designator : Expr->designators()) { + if (!Designator.isFieldDesignator()) +continue; + FieldDecl *FD = Designator.getFieldDecl(); + if (!FD) +continue; + IdentifierInfo *II = FD->getIdentifier(); + if (!II) +continue; + SourceRange FixLocation{Designator.getFieldLoc(), + Designator.getFieldLoc()}; + Check->addUsage(FD, FixLocation, SM); +} + +return true; + } + private: RenamerClangTidyCheck *Check; const SourceManager *SM; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 309b844615a121..e076281bd5fafe 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -254,7 +254,8 @@ Changes in existing checks - Improved :doc:`readability-identifier-naming ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian - Prefix when configured to `LowerCase`. + Prefix when configured to `LowerCase`. Added support for renaming designated + initializers. - Improved :doc:`readability-implicit-bool-conversion ` check to provide 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..57ef4aae5ddb78 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 @@ -766,3 +766,13 @@ STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr) {} // CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t) {} #undef STATIC_MACRO } + +struct Some_struct { + int SomeMember; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for public member 'SomeMember' [readability-identifier-naming] +// CHECK-FIXES: {{^}} int some_member; +}; +Some_struct g_s1{ .SomeMember = 1 }; +// CHECK-FIXES: {{^}}Some_struct g_s1{ .some_member = 1 }; +Some_struct g_s2{.SomeMember=1}; +// CHECK-FIXES: {{^}}Some_struct g_s2{.some_member=1}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Support renaming designated initializers (PR #86976)
@@ -367,6 +367,25 @@ class RenamerClangTidyVisitor return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) { +for (const auto &Designator : Expr->designators()) { + if (!Designator.isFieldDesignator()) +continue; + auto *FieldDecl = Designator.getFieldDecl(); + if (!FieldDecl) +continue; + auto *II = FieldDecl->getIdentifier(); + if (!II) +continue; + SourceRange FixLocation{ + Designator.getFieldLoc(), + Designator.getFieldLoc().getLocWithOffset(II->getLength())}; revane wrote: You're right. Good to know! https://github.com/llvm/llvm-project/pull/86976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Support renaming designated initializers (PR #86976)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/86976 >From aabdf0019baf4357eb45c6219ff4881b46636e47 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:24:34 -0400 Subject: [PATCH] Support renaming designated initializers Until now, they were just ignored by RenamerClangTidyCheck. --- .../utils/RenamerClangTidyCheck.cpp | 23 --- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++- .../readability/identifier-naming.cpp | 10 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index da1433aa2d05d4..6606f456261a64 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 { using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId; static inline NamingCheckId getEmptyKey() { -return {DenseMapInfo::getEmptyKey(), - "EMPTY"}; +return {DenseMapInfo::getEmptyKey(), "EMPTY"}; } static inline NamingCheckId getTombstoneKey() { return {DenseMapInfo::getTombstoneKey(), - "TOMBSTONE"}; +"TOMBSTONE"}; } static unsigned getHashValue(NamingCheckId Val) { @@ -367,6 +366,24 @@ class RenamerClangTidyVisitor return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) { +for (const auto &Designator : Expr->designators()) { + if (!Designator.isFieldDesignator()) +continue; + const FieldDecl *FD = Designator.getFieldDecl(); + if (!FD) +continue; + const IdentifierInfo *II = FD->getIdentifier(); + if (!II) +continue; + SourceRange FixLocation{Designator.getFieldLoc(), + Designator.getFieldLoc()}; + Check->addUsage(FD, FixLocation, SM); +} + +return true; + } + private: RenamerClangTidyCheck *Check; const SourceManager *SM; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 309b844615a121..e076281bd5fafe 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -254,7 +254,8 @@ Changes in existing checks - Improved :doc:`readability-identifier-naming ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian - Prefix when configured to `LowerCase`. + Prefix when configured to `LowerCase`. Added support for renaming designated + initializers. - Improved :doc:`readability-implicit-bool-conversion ` check to provide 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..57ef4aae5ddb78 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 @@ -766,3 +766,13 @@ STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr) {} // CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t) {} #undef STATIC_MACRO } + +struct Some_struct { + int SomeMember; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for public member 'SomeMember' [readability-identifier-naming] +// CHECK-FIXES: {{^}} int some_member; +}; +Some_struct g_s1{ .SomeMember = 1 }; +// CHECK-FIXES: {{^}}Some_struct g_s1{ .some_member = 1 }; +Some_struct g_s2{.SomeMember=1}; +// CHECK-FIXES: {{^}}Some_struct g_s2{.some_member=1}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Support renaming designated initializers (PR #86976)
@@ -367,6 +367,24 @@ class RenamerClangTidyVisitor return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) { +for (const auto &Designator : Expr->designators()) { + if (!Designator.isFieldDesignator()) +continue; + FieldDecl *FD = Designator.getFieldDecl(); revane wrote: Sorry. I forgot that request. https://github.com/llvm/llvm-project/pull/86976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: clang-tools-extra code owners
I don't know of anyone who has a stake in clang-modernize and I probably should be removed from the code-owner role. On 2 September 2015 at 12:48, Manuel Klimek wrote: > I think that basically encodes what the current state is, and we should > have kept that file in a better shape. +Edwin in case he still has a stake > in clang-modernize, or knows who might have. > > On Wed, Sep 2, 2015 at 6:38 PM Aaron Ballman > wrote: > >> I happened to notice that CODE_OWNERS.TXT for clang-tools-extra is >> rather sparse. These tools are starting to get more attention from the >> community, and I am wondering whether it would make sense to populate >> that somewhat? If so, I would nominate: >> >> Alexander Kornienko for clang-tidy >> Peter Collingbourne for clang-query >> Manuel Klimek for clang-rename, and clang-tools-extra as a whole >> >> I'm basing these nominations on who is actively maintaining the tools >> already. >> >> ~Aaron >> > -- Edwin V ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
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 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 { using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId; static inline NamingCheckId getEmptyKey() { -return {DenseMapInfo::getEmptyKey(), - "EMPTY"}; +return {DenseMapInfo::getEmptyKey(), "EMPTY"}; } static inline NamingCheckId getTombstoneKey() { return {DenseMapInfo::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 struct a { // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
revane wrote: Macros are tricky business and I understand why renaming is not allowed within macros. For the cases in the lit test, the renaming seems safe. Is this generally the case (i.e. those permitted by `clang::tidy::utils::rangeCanBeFixed()`)? What other test cases can we add? Or is this change just not safe? If so, how can we update the "InsideMacro" tests to actually fail even in the presence of a SourceManager. https://github.com/llvm/llvm-project/pull/87792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
revane wrote: @AaronBallman What do you think? https://github.com/llvm/llvm-project/pull/87792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] rename designated initializers (PR #86976)
revane wrote: @AaronBallman Ready to go? https://github.com/llvm/llvm-project/pull/86976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
revane wrote: Indeed. I can add some tests to make sure nested macros aren't affected but my thought was since this change allows renaming _arguments_ (i.e. not the macro parameters) then it was safe since the code is not really "inside a macro". There are already other means to filter out system headers and other user-defined headers. I couldn't come up with other classes of errors where this replacement would be invalid. https://github.com/llvm/llvm-project/pull/87792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
revane wrote: Using the suggested code and this one usage: ``` MY_MACRO(myglob); ``` No suggestion is made. My understanding is because the full range of the NamedDecl would contain `awesome_myglob` which isn't entirely within a macro arg. https://github.com/llvm/llvm-project/pull/87792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/87792 >From b34156654bfa937b180eaad1061e38c10a799235 Mon Sep 17 00:00:00 2001 From: Edwin Vane 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. --- .../utils/RenamerClangTidyCheck.cpp | 7 +++--- .../readability/identifier-naming.cpp | 23 +++ 2 files changed, 21 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 { using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId; static inline NamingCheckId getEmptyKey() { -return {DenseMapInfo::getEmptyKey(), - "EMPTY"}; +return {DenseMapInfo::getEmptyKey(), "EMPTY"}; } static inline NamingCheckId getTombstoneKey() { return {DenseMapInfo::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..438cb5ea8a54c3 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,20 @@ 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) {} + +#define MY_CAT_IMPL(l, r) l ## r +#define MY_CAT(l, r) MY_CAT_IMPL(l, r) +#define MY_MACRO2(foo) int MY_CAT(awesome_, MY_CAT(foo, __COUNTER__)) = 0 +#define MY_MACRO3(foo) int MY_CAT(awesome_, foo) = 0 +MY_MACRO2(myglob); +MY_MACRO3(myglob); +// No suggestions should occur even though the resulting decl of awesome_myglob# +// or awesome_myglob are not entirely within a macro argument. + +} // namespace InlineNamespace +} // namespace FOO_NS template struct a { // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
revane wrote: Already done. Unless you had something else in mind? https://github.com/llvm/llvm-project/pull/87792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane created https://github.com/llvm/llvm-project/pull/88186 Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. >From 596037423faeebf01759158b5a93a3e933978941 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- .../test/clang-tidy/check_clang_tidy.py | 85 +-- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..38728df5c48716 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -102,14 +114,15 @@ def __init__(self, args, extra_args): self.clang_tidy_extra_args = extra_args if "--" in extra_args: i = self.clang_tidy_extra_args.index("--") -self.clang_extra_args = self.clang_tidy_extra_args[i + 1 :] +self.clang_extra_args = self.clang_tidy_extra_args[i + 1:] self.clang_tidy_extra_args = self.clang_tidy_extra_args[:i] # If the test does not specify a config style, force an empty one; otherwise # auto-detection logic can discover a ".clang-tidy" file that is not related to # the test. if not any( -[re.match("^-?-config(-file)?=", arg) for arg in self.clang_tidy_extra_args] +[re.match("^-?-config(-file)?=", arg) + for arg in self.clang_tidy_extra_args] ): self.clang_tidy_extra_args.append("--config={}") @@ -128,7 +141,8 @@ def __init__(self, args, extra_args): self.clang_extra_args.append("-nostdinc++") if self.resource_dir is not None: -self.clang_extra_args.append("-resource-dir=%s" % self.resource_dir) +self.clang_extra_args.append( +"-resource-dir=%s" % self.resource_dir) def read_input(self): with open(self.input_file_name, "r", encoding="utf-8") as input_file: @@ -144,13 +158,16 @@ def get_prefixes(self): file_check_suffix = ("-" + suffix) if suffix else "" -has_check_fix = self.fixes.check(file_check_suffix, self.input_text) +has_check_fix = self.fixes.check( +file_check_suffix, self.input_text) self.has_check_fixes = self.has_check_fixes or has_check_fix -has_check_message = self.messages.c
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 631ac048e4b8fcbc242be54f48e5bf432a6a5b3d Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- .../test/clang-tidy/check_clang_tidy.py | 70 ++- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +) parser.add_argument("-expect-clang-tidy-error", action="store_true") parser.add_argument("-resource-dir") parser.add_argument("-assume-filename") @@ -298,7 +318,19 @@ def parse_arguments(): type=csv, help="comma-separated list of FileCheck suffixes", ) -parser.add_argument("-std", type=csv, default=["c++11-or-later"]) +parser.add_argument( +"-export", +default=None, +type=str, +metavar="file", +help="A file to export fixes into instead of fixing.", +) +parser.add_argument( +"-std", +type=csv, +default=["c++11-or-later"], +help="Passed to clang. Special -or-later values are expanded.", +) return parser.parse_known_args() ___
[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/87792 >From c354f7f0be526fe41a56198c5d0ca434a8ad0bfe Mon Sep 17 00:00:00 2001 From: Edwin Vane 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. --- .../utils/RenamerClangTidyCheck.cpp | 2 +- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- .../readability/identifier-naming.cpp | 23 +++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 69b7d40ef628d6..ad8048e2a92b7e 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -489,7 +489,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/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a7193e90c38da2..b66be44e9f8a6f 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -268,7 +268,7 @@ Changes in existing checks ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian Prefix when configured to `LowerCase`. Added support for renaming designated - initializers. + initializers. Added support for renaming macro arguments. - Improved :doc:`readability-implicit-bool-conversion ` check to provide 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 57ef4aae5ddb78..99149fe86aceec 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,20 @@ 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) {} + +#define MY_CAT_IMPL(l, r) l ## r +#define MY_CAT(l, r) MY_CAT_IMPL(l, r) +#define MY_MACRO2(foo) int MY_CAT(awesome_, MY_CAT(foo, __COUNTER__)) = 0 +#define MY_MACRO3(foo) int MY_CAT(awesome_, foo) = 0 +MY_MACRO2(myglob); +MY_MACRO3(myglob); +// No suggestions should occur even though the resulting decl of awesome_myglob# +// or awesome_myglob are not entirely within a macro argument. + +} // namespace InlineNamespace +} // namespace FOO_NS template struct a { // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From bc5071c54e825d7036b6a54f4dfa02268e3a5c72 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- .../test/clang-tidy/check_clang_tidy.py | 70 ++- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +) parser.add_argument("-expect-clang-tidy-error", action="store_true") parser.add_argument("-resource-dir") parser.add_argument("-assume-filename") @@ -298,7 +318,19 @@ def parse_arguments(): type=csv, help="comma-separated list of FileCheck suffixes", ) -parser.add_argument("-std", type=csv, default=["c++11-or-later"]) +parser.add_argument( +"-export", +default=None, +type=str, +metavar="file", +help="A file to export fixes into instead of fixing.", +) +parser.add_argument( +"-std", +type=csv, +default=["c++11-or-later"], +help="Passed to clang. Special -or-later values are expanded.", +) return parser.parse_known_args() ___
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 70 ++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..59d50f49120fc0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +) parser.add_argument("-expect-clang-tidy-error", action="store
[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)
https://github.com/revane created https://github.com/llvm/llvm-project/pull/88268 Some functions allow a null SourceManager, no SourceManager, or a SourceManager in an inconsistent argument position. Since SourceManager is generally not null and it doesn't make sense to apply renaming without one, these inconsistencies are now gone. >From 9808bf777883ecdb041db92e1f611be5ff82996a Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:25:06 -0400 Subject: [PATCH] [clang-tidy] Simplify RenamerClangTidyCheck API Some functions allow a null SourceManager, no SourceManager, or a SourceManager in an inconsistent argument position. Since SourceManager is generally not null and it doesn't make sense to apply renaming without one, these inconsistencies are now gone. --- .../utils/RenamerClangTidyCheck.cpp | 46 +++ .../clang-tidy/utils/RenamerClangTidyCheck.h | 11 +++-- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index ad8048e2a92b7e..962a243ce94d48 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -169,14 +169,14 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks { return; if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation())) return; -Check->checkMacro(SM, MacroNameTok, Info); +Check->checkMacro(MacroNameTok, Info, SM); } /// MacroExpands calls expandMacro for macros in the main file void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange /*Range*/, const MacroArgs * /*Args*/) override { -Check->expandMacro(MacroNameTok, MD.getMacroInfo()); +Check->expandMacro(MacroNameTok, MD.getMacroInfo(), SM); } private: @@ -187,7 +187,7 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks { class RenamerClangTidyVisitor : public RecursiveASTVisitor { public: - RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager *SM, + RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager &SM, bool AggressiveDependentMemberLookup) : Check(Check), SM(SM), AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {} @@ -258,7 +258,7 @@ class RenamerClangTidyVisitor // Fix overridden methods if (const auto *Method = dyn_cast(Decl)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) { -Check->addUsage(Overridden, Method->getLocation()); +Check->addUsage(Overridden, Method->getLocation(), SM); return true; // Don't try to add the actual decl as a Failure. } } @@ -268,7 +268,7 @@ class RenamerClangTidyVisitor if (isa(Decl)) return true; -Check->checkNamedDecl(Decl, *SM); +Check->checkNamedDecl(Decl, SM); return true; } @@ -385,7 +385,7 @@ class RenamerClangTidyVisitor private: RenamerClangTidyCheck *Check; - const SourceManager *SM; + const SourceManager &SM; const bool AggressiveDependentMemberLookup; }; @@ -415,7 +415,7 @@ void RenamerClangTidyCheck::registerPPCallbacks( void RenamerClangTidyCheck::addUsage( const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range, -const SourceManager *SourceMgr) { +const SourceManager &SourceMgr) { // Do nothing if the provided range is invalid. if (Range.isInvalid()) return; @@ -425,8 +425,7 @@ void RenamerClangTidyCheck::addUsage( // spelling location to different source locations, and we only want to fix // the token once, before it is expanded by the macro. SourceLocation FixLocation = Range.getBegin(); - if (SourceMgr) -FixLocation = SourceMgr->getSpellingLoc(FixLocation); + FixLocation = SourceMgr.getSpellingLoc(FixLocation); if (FixLocation.isInvalid()) return; @@ -440,15 +439,15 @@ void RenamerClangTidyCheck::addUsage( if (!Failure.shouldFix()) return; - if (SourceMgr && SourceMgr->isWrittenInScratchSpace(FixLocation)) + if (SourceMgr.isWrittenInScratchSpace(FixLocation)) Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro; - if (!utils::rangeCanBeFixed(Range, SourceMgr)) + if (!utils::rangeCanBeFixed(Range, &SourceMgr)) Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro; } void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range, - const SourceManager *SourceMgr) { + const SourceManager &SourceMgr) { // Don't keep track for non-identifier names. auto *II = Decl->getIdentifier(); if (!II) @@ -489,18 +488,24 @@ void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl, } Failure.Info = std::move(Info); - ad
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
revane wrote: @PiotrZSL @carlosgalvezp @LegalizeAdulthood @njames93 For your consideration. https://github.com/llvm/llvm-project/pull/88186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)
revane wrote: @PiotrZSL @carlosgalvezp @LegalizeAdulthood @njames93 For your consideration. https://github.com/llvm/llvm-project/pull/88268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 8dda3028dc7f83ced4cdc2475858075d45e04646 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 4 +- .../test/clang-tidy/check_clang_tidy.py | 70 ++- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..b745ac1e886336 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -99,7 +99,9 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a - similar fashion to what `-header-filter` does for header files. + similar fashion to what `-header-filter` does for header files. Improved + :program:`check_clang_tidy.py` script. Added argument `-export` to aid in + clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
@@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export` revane wrote: Done. Could you explain the rules for when new points are warranted? It appears there is a new point for each checker so I guessed there would be a new point for each different tool. https://github.com/llvm/llvm-project/pull/88186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 70 ++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..59d50f49120fc0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +) parser.add_argument("-expect-clang-tidy-error", action="store
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 70 ++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..59d50f49120fc0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..4065eb5cbf2cdb 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export, the tool simply exports fixes to a provided file +and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export is None else "--export-fixes=" + self.export] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +) parser.add_argument("-expect-clang-tidy-error", action="store
[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)
revane wrote: I don't have write access. Would someone please land the PR for me? https://github.com/llvm/llvm-project/pull/88268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)
revane wrote: @AaronBallman I can't land this PR. https://github.com/llvm/llvm-project/pull/88268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
revane wrote: @AaronBallman Other reviewers you would suggest? https://github.com/llvm/llvm-project/pull/88186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From b01f3305c350afb543afb37cc9f8b98be3ccb06c Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export-fixes flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 72 +-- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..1405fb0df1f8dd 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..3cee5df58d5c8c 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#rgs!/usr/bin/env python3 # # ===- check_clang_tidy.py - ClangTidy Test Helper *- python -*--===# # @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export-fixes, the tool simply exports fixes to a provided +file and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export_fixes = args.export_fixes self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export_fixes is None else "--export-fixes=" + self.export_fixes] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export_fixes is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export_fixes is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.Argumen
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export = args.export revane wrote: Done https://github.com/llvm/llvm-project/pull/88186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
@@ -298,7 +318,19 @@ def parse_arguments(): type=csv, help="comma-separated list of FileCheck suffixes", ) -parser.add_argument("-std", type=csv, default=["c++11-or-later"]) +parser.add_argument( +"-export", revane wrote: Done https://github.com/llvm/llvm-project/pull/88186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From b9cc1681c73a8af31df38e5f96cf19f14dbc0ccd Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export-fixes flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 70 ++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..1405fb0df1f8dd 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..291a70e37827c0 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export-fixes, the tool simply exports fixes to a provided +file and does not run FileCheck. + +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export_fixes = args.export_fixes self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,9 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ ["-fix" if self.export_fixes is None else "--export-fixes=" + self.export_fixes] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export_fixes is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export_fixes is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +300,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +formatter_class=argparse.RawDescriptionHelpFormatter, +)
[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88186 >From 0c1f7d83c765a6c829543db9719420f7bf7eb02d Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 9 Apr 2024 16:07:52 -0400 Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py Makes it possible to export fixes from running llvm-lit on a clang-tidy test. To enable, modify the RUN invocation directly in the test with the new -export-fixes flag. llvm-lit will report the test passed and fixes can be found in the file specified to the -export flag. --- clang-tools-extra/docs/ReleaseNotes.rst | 2 + .../test/clang-tidy/check_clang_tidy.py | 74 ++- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b66be44e9f8a6f..1405fb0df1f8dd 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` to filter source files from the compilation database, via a RegEx. In a similar fashion to what `-header-filter` does for header files. +- Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes` + to aid in clang-tidy and test development. New checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py index 53ffca0bad8d06..6d4b466afa691a 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -8,25 +8,35 @@ # # ======# -r""" +""" ClangTidy Test Helper = -This script runs clang-tidy in fix mode and verify fixes, messages or both. +This script is used to simplify writing, running, and debugging tests compatible +with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to +verify messages and/or fixes. + +For debugging, with --export-fixes, the tool simply exports fixes to a provided +file and does not run FileCheck. -Usage: - check_clang_tidy.py [-resource-dir=] \ -[-assume-filename=] \ -[-check-suffix=] \ -[-check-suffixes=] \ -[-std=c++(98|11|14|17|20)[-or-later]] \ - \ --- [optional clang-tidy arguments] +Extra arguments, those after the first -- if any, are passed to either +clang-tidy or clang: +* Arguments between the first -- and second -- are clang-tidy arguments. + * May be only whitespace if there are no clang-tidy arguments. + * clang-tidy's --config would go here. +* Arguments after the second -- are clang arguments + +Examples + -Example: // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs -Notes: +or + + // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t -std=c++20 + +Notes +- -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. @@ -34,6 +44,7 @@ import argparse import os +import pathlib import re import subprocess import sys @@ -88,6 +99,7 @@ def __init__(self, args, extra_args): self.has_check_fixes = False self.has_check_messages = False self.has_check_notes = False +self.export_fixes = args.export_fixes self.fixes = MessagePrefix("CHECK-FIXES") self.messages = MessagePrefix("CHECK-MESSAGES") self.notes = MessagePrefix("CHECK-NOTES") @@ -181,7 +193,13 @@ def run_clang_tidy(self): [ "clang-tidy", self.temp_file_name, -"-fix", +] ++ [ +"-fix" +if self.export_fixes is None +else "--export-fixes=" + self.export_fixes +] ++ [ "--checks=-*," + self.check_name, ] + self.clang_tidy_extra_args @@ -255,12 +273,14 @@ def check_notes(self, clang_tidy_output): def run(self): self.read_input() -self.get_prefixes() +if self.export_fixes is None: +self.get_prefixes() self.prepare_test_inputs() clang_tidy_output = self.run_clang_tidy() -self.check_fixes() -self.check_messages(clang_tidy_output) -self.check_notes(clang_tidy_output) +if self.export_fixes is None: +self.check_fixes() +self.check_messages(clang_tidy_output) +self.check_notes(clang_tidy_output) def expand_std(std): @@ -284,7 +304,11 @@ def csv(string): def parse_arguments(): -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser( +prog=pathlib.Path(__file__).stem, +description=__doc__, +
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
https://github.com/revane created https://github.com/llvm/llvm-project/pull/88735 The handling of renaming failures and multiple usages related to those failures is currently spread over several functions. Identifying the failure NamedDecl for a given usage is also duplicated, once when creating failures and again when identify usages. There are currently two ways to a failed NamedDecl from a usage: use the canonical decl or use the overridden method. With new methods about to be added, a cleanup was in order. The data flow is simplified as follows: * The visitor always forwards NamedDecls to addUsage(NamedDecl). * addUsage(NamedDecl) determines the failed NamedDecl and determines potential new names based on that failure. Usages are registered using addUsage(NamingCheckId). * addUsage(NamingCheckId) is now protected and its single responsibility is maintaining the integrity of the failure/usage map. >From 16271c2988994257d33a3f6b2b98254be2587b58 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:30:32 -0400 Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed The handling of renaming failures and multiple usages related to those failures is currently spread over several functions. Identifying the failure NamedDecl for a given usage is also duplicated, once when creating failures and again when identify usages. There are currently two ways to a failed NamedDecl from a usage: use the canonical decl or use the overridden method. With new methods about to be added, a cleanup was in order. The data flow is simplified as follows: * The visitor always forwards NamedDecls to addUsage(NamedDecl). * addUsage(NamedDecl) determines the failed NamedDecl and determines potential new names based on that failure. Usages are registered using addUsage(NamingCheckId). * addUsage(NamingCheckId) is now protected and its single responsibility is maintaining the integrity of the failure/usage map. --- .../utils/RenamerClangTidyCheck.cpp | 194 ++ .../clang-tidy/utils/RenamerClangTidyCheck.h | 14 +- 2 files changed, 111 insertions(+), 97 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 962a243ce94d48..453d5a754f12fc 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -61,6 +61,44 @@ struct DenseMapInfo { namespace clang::tidy { namespace { +/// Returns the function that \p Method is overridding. If There are none or +/// multiple overrides it returns nullptr. If the overridden function itself is +/// overridding then it will recurse up to find the first decl of the function. +const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { + if (Method->size_overridden_methods() != 1) +return nullptr; + + while (true) { +Method = *Method->begin_overridden_methods(); +assert(Method && "Overridden method shouldn't be null"); +unsigned NumOverrides = Method->size_overridden_methods(); +if (NumOverrides == 0) + return Method; +if (NumOverrides > 1) + return nullptr; + } +} + +bool hasNoName(const NamedDecl *Decl) { + return !Decl->getIdentifier() || Decl->getName().empty(); +} + +const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { + const auto *Canonical = cast(ND->getCanonicalDecl()); + if (Canonical != ND) +return Canonical; + + if (const auto *Method = dyn_cast(ND)) { +if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) + Canonical = cast(Overridden->getCanonicalDecl()); + +if (Canonical != ND) + return Canonical; + } + + return ND; +} + class NameLookup { llvm::PointerIntPair Data; @@ -132,24 +170,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl &Parent, return NameLookup(Found); // If nullptr, decl wasn't found. } -/// Returns the function that \p Method is overridding. If There are none or -/// multiple overrides it returns nullptr. If the overridden function itself is -/// overridding then it will recurse up to find the first decl of the function. -static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { - if (Method->size_overridden_methods() != 1) -return nullptr; - - while (true) { -Method = *Method->begin_overridden_methods(); -assert(Method && "Overridden method shouldn't be null"); -unsigned NumOverrides = Method->size_overridden_methods(); -if (NumOverrides == 0) - return Method; -if (NumOverrides > 1) - return nullptr; - } -} - namespace { /// Callback supplies macros to RenamerClangTidyCheck::checkMacro @@ -192,10 +212,6 @@ class RenamerClangTidyVisitor : Check(Check), SM(SM), AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {} - static bool hasNoName(const NamedDecl *Decl) { -return !Decl->getIdentifier() || Decl->getName
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
revane wrote: @PiotrZSL Second-last in the sequence of PRs which fix another renaming issue. https://github.com/llvm/llvm-project/pull/88735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88735 >From 2249f8c4e28297d72d6f5d36e883b921116f33e4 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:30:32 -0400 Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed The handling of renaming failures and multiple usages related to those failures is currently spread over several functions. Identifying the failure NamedDecl for a given usage is also duplicated, once when creating failures and again when identify usages. There are currently two ways to a failed NamedDecl from a usage: use the canonical decl or use the overridden method. With new methods about to be added, a cleanup was in order. The data flow is simplified as follows: * The visitor always forwards NamedDecls to addUsage(NamedDecl). * addUsage(NamedDecl) determines the failed NamedDecl and determines potential new names based on that failure. Usages are registered using addUsage(NamingCheckId). * addUsage(NamingCheckId) is now protected and its single responsibility is maintaining the integrity of the failure/usage map. --- .../utils/RenamerClangTidyCheck.cpp | 196 ++ .../clang-tidy/utils/RenamerClangTidyCheck.h | 14 +- 2 files changed, 113 insertions(+), 97 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 962a243ce94d48..f5ed617365403a 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -61,6 +61,7 @@ struct DenseMapInfo { namespace clang::tidy { namespace { + class NameLookup { llvm::PointerIntPair Data; @@ -78,6 +79,7 @@ class NameLookup { operator bool() const { return !hasMultipleResolutions(); } const NamedDecl *operator*() const { return getDecl(); } }; + } // namespace static const NamedDecl *findDecl(const RecordDecl &RecDecl, @@ -91,6 +93,44 @@ static const NamedDecl *findDecl(const RecordDecl &RecDecl, return nullptr; } +/// Returns the function that \p Method is overridding. If There are none or +/// multiple overrides it returns nullptr. If the overridden function itself is +/// overridding then it will recurse up to find the first decl of the function. +static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { + if (Method->size_overridden_methods() != 1) +return nullptr; + + while (true) { +Method = *Method->begin_overridden_methods(); +assert(Method && "Overridden method shouldn't be null"); +unsigned NumOverrides = Method->size_overridden_methods(); +if (NumOverrides == 0) + return Method; +if (NumOverrides > 1) + return nullptr; + } +} + +static bool hasNoName(const NamedDecl *Decl) { + return !Decl->getIdentifier() || Decl->getName().empty(); +} + +static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { + const auto *Canonical = cast(ND->getCanonicalDecl()); + if (Canonical != ND) +return Canonical; + + if (const auto *Method = dyn_cast(ND)) { +if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) + Canonical = cast(Overridden->getCanonicalDecl()); + +if (Canonical != ND) + return Canonical; + } + + return ND; +} + /// Returns a decl matching the \p DeclName in \p Parent or one of its base /// classes. If \p AggressiveTemplateLookup is `true` then it will check /// template dependent base classes as well. @@ -132,24 +172,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl &Parent, return NameLookup(Found); // If nullptr, decl wasn't found. } -/// Returns the function that \p Method is overridding. If There are none or -/// multiple overrides it returns nullptr. If the overridden function itself is -/// overridding then it will recurse up to find the first decl of the function. -static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { - if (Method->size_overridden_methods() != 1) -return nullptr; - - while (true) { -Method = *Method->begin_overridden_methods(); -assert(Method && "Overridden method shouldn't be null"); -unsigned NumOverrides = Method->size_overridden_methods(); -if (NumOverrides == 0) - return Method; -if (NumOverrides > 1) - return nullptr; - } -} - namespace { /// Callback supplies macros to RenamerClangTidyCheck::checkMacro @@ -192,10 +214,6 @@ class RenamerClangTidyVisitor : Check(Check), SM(SM), AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {} - static bool hasNoName(const NamedDecl *Decl) { -return !Decl->getIdentifier() || Decl->getName().empty(); - } - bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return false; } @@ -246,29 +264,10 @@ class RenamerClangTidyVisitor } bool VisitNamedDecl(NamedDecl *Decl) { -if (hasNoName(Decl)) -
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
@@ -61,6 +61,44 @@ struct DenseMapInfo { namespace clang::tidy { namespace { +/// Returns the function that \p Method is overridding. If There are none or +/// multiple overrides it returns nullptr. If the overridden function itself is +/// overridding then it will recurse up to find the first decl of the function. +const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { revane wrote: Ah. Good to know. https://github.com/llvm/llvm-project/pull/88735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88735 >From 5be7a57838b8fe7042e0719911670f6f369db2e8 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:30:32 -0400 Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed The handling of renaming failures and multiple usages related to those failures is currently spread over several functions. Identifying the failure NamedDecl for a given usage is also duplicated, once when creating failures and again when identify usages. There are currently two ways to a failed NamedDecl from a usage: use the canonical decl or use the overridden method. With new methods about to be added, a cleanup was in order. The data flow is simplified as follows: * The visitor always forwards NamedDecls to addUsage(NamedDecl). * addUsage(NamedDecl) determines the failed NamedDecl and determines potential new names based on that failure. Usages are registered using addUsage(NamingCheckId). * addUsage(NamingCheckId) is now protected and its single responsibility is maintaining the integrity of the failure/usage map. --- .../utils/RenamerClangTidyCheck.cpp | 196 ++ .../clang-tidy/utils/RenamerClangTidyCheck.h | 14 +- 2 files changed, 113 insertions(+), 97 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 962a243ce94d48..f5ed617365403a 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -61,6 +61,7 @@ struct DenseMapInfo { namespace clang::tidy { namespace { + class NameLookup { llvm::PointerIntPair Data; @@ -78,6 +79,7 @@ class NameLookup { operator bool() const { return !hasMultipleResolutions(); } const NamedDecl *operator*() const { return getDecl(); } }; + } // namespace static const NamedDecl *findDecl(const RecordDecl &RecDecl, @@ -91,6 +93,44 @@ static const NamedDecl *findDecl(const RecordDecl &RecDecl, return nullptr; } +/// Returns the function that \p Method is overridding. If There are none or +/// multiple overrides it returns nullptr. If the overridden function itself is +/// overridding then it will recurse up to find the first decl of the function. +static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { + if (Method->size_overridden_methods() != 1) +return nullptr; + + while (true) { +Method = *Method->begin_overridden_methods(); +assert(Method && "Overridden method shouldn't be null"); +unsigned NumOverrides = Method->size_overridden_methods(); +if (NumOverrides == 0) + return Method; +if (NumOverrides > 1) + return nullptr; + } +} + +static bool hasNoName(const NamedDecl *Decl) { + return !Decl->getIdentifier() || Decl->getName().empty(); +} + +static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { + const auto *Canonical = cast(ND->getCanonicalDecl()); + if (Canonical != ND) +return Canonical; + + if (const auto *Method = dyn_cast(ND)) { +if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) + Canonical = cast(Overridden->getCanonicalDecl()); + +if (Canonical != ND) + return Canonical; + } + + return ND; +} + /// Returns a decl matching the \p DeclName in \p Parent or one of its base /// classes. If \p AggressiveTemplateLookup is `true` then it will check /// template dependent base classes as well. @@ -132,24 +172,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl &Parent, return NameLookup(Found); // If nullptr, decl wasn't found. } -/// Returns the function that \p Method is overridding. If There are none or -/// multiple overrides it returns nullptr. If the overridden function itself is -/// overridding then it will recurse up to find the first decl of the function. -static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { - if (Method->size_overridden_methods() != 1) -return nullptr; - - while (true) { -Method = *Method->begin_overridden_methods(); -assert(Method && "Overridden method shouldn't be null"); -unsigned NumOverrides = Method->size_overridden_methods(); -if (NumOverrides == 0) - return Method; -if (NumOverrides > 1) - return nullptr; - } -} - namespace { /// Callback supplies macros to RenamerClangTidyCheck::checkMacro @@ -192,10 +214,6 @@ class RenamerClangTidyVisitor : Check(Check), SM(SM), AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {} - static bool hasNoName(const NamedDecl *Decl) { -return !Decl->getIdentifier() || Decl->getName().empty(); - } - bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return false; } @@ -246,29 +264,10 @@ class RenamerClangTidyVisitor } bool VisitNamedDecl(NamedDecl *Decl) { -if (hasNoName(Decl)) -
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/88735 >From 64c1b5b7d6c29c86e0e7f26f0eff3b7a52f95e7e Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Thu, 28 Mar 2024 09:30:32 -0400 Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed The handling of renaming failures and multiple usages related to those failures is currently spread over several functions. Identifying the failure NamedDecl for a given usage is also duplicated, once when creating failures and again when identify usages. There are currently two ways to a failed NamedDecl from a usage: use the canonical decl or use the overridden method. With new methods about to be added, a cleanup was in order. The data flow is simplified as follows: * The visitor always forwards NamedDecls to addUsage(NamedDecl). * addUsage(NamedDecl) determines the failed NamedDecl and determines potential new names based on that failure. Usages are registered using addUsage(NamingCheckId). * addUsage(NamingCheckId) is now protected and its single responsibility is maintaining the integrity of the failure/usage map. --- .../bugprone/ReservedIdentifierCheck.cpp | 5 +- .../readability/IdentifierNamingCheck.cpp | 4 + .../utils/RenamerClangTidyCheck.cpp | 196 ++ .../clang-tidy/utils/RenamerClangTidyCheck.h | 14 +- 4 files changed, 121 insertions(+), 98 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp index f6714d056518d..53956661d57d1 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp @@ -178,8 +178,11 @@ std::optional ReservedIdentifierCheck::getDeclFailureInfo(const NamedDecl *Decl, const SourceManager &) const { assert(Decl && Decl->getIdentifier() && !Decl->getName().empty() && - !Decl->isImplicit() && "Decl must be an explicit identifier with a name."); + // Implicit identifiers cannot fail. + if (Decl->isImplicit()) +return std::nullopt; + return getFailureInfoImpl( Decl->getName(), isa(Decl->getDeclContext()), /*IsMacro = */ false, getLangOpts(), Invert, AllowedIdentifiers); diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index dc30531ebda0e..27a12bfc58068 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -1374,6 +1374,10 @@ IdentifierNamingCheck::getFailureInfo( std::optional IdentifierNamingCheck::getDeclFailureInfo(const NamedDecl *Decl, const SourceManager &SM) const { + // Implicit identifiers cannot be renamed. + if (Decl->isImplicit()) +return std::nullopt; + SourceLocation Loc = Decl->getLocation(); const FileStyle &FileStyle = getStyleForFile(SM.getFilename(Loc)); if (!FileStyle.isActive()) diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 962a243ce94d4..f5ed617365403 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -61,6 +61,7 @@ struct DenseMapInfo { namespace clang::tidy { namespace { + class NameLookup { llvm::PointerIntPair Data; @@ -78,6 +79,7 @@ class NameLookup { operator bool() const { return !hasMultipleResolutions(); } const NamedDecl *operator*() const { return getDecl(); } }; + } // namespace static const NamedDecl *findDecl(const RecordDecl &RecDecl, @@ -91,6 +93,44 @@ static const NamedDecl *findDecl(const RecordDecl &RecDecl, return nullptr; } +/// Returns the function that \p Method is overridding. If There are none or +/// multiple overrides it returns nullptr. If the overridden function itself is +/// overridding then it will recurse up to find the first decl of the function. +static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) { + if (Method->size_overridden_methods() != 1) +return nullptr; + + while (true) { +Method = *Method->begin_overridden_methods(); +assert(Method && "Overridden method shouldn't be null"); +unsigned NumOverrides = Method->size_overridden_methods(); +if (NumOverrides == 0) + return Method; +if (NumOverrides > 1) + return nullptr; + } +} + +static bool hasNoName(const NamedDecl *Decl) { + return !Decl->getIdentifier() || Decl->getName().empty(); +} + +static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { + const auto *Canonical = cast(ND->getCanonicalDecl()); + if (Canonical != ND) +return Canonical; + + if (const auto *Method = dyn_cast(ND)) { +if (const CXXMethodD
[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)
revane wrote: @PiotrZSL I finally got a windows environment set up and fixed the windows build error. Would you merge for me since I don't have permission? https://github.com/llvm/llvm-project/pull/88735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
https://github.com/revane created https://github.com/llvm/llvm-project/pull/91954 Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration. >From 62635498da1dbec26e491f64f6077ec1381909b8 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Mon, 15 Apr 2024 09:38:48 -0400 Subject: [PATCH] [clang-tidy] Rename out-of-line function definitions Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration. --- .../utils/RenamerClangTidyCheck.cpp | 3 ++ clang-tools-extra/docs/ReleaseNotes.rst | 3 +- .../readability/identifier-naming-ool.cpp | 30 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index e811f5519de2c..2959946f51b54 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -123,6 +123,9 @@ static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { if (const auto *Method = dyn_cast(ND)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Canonical = cast(Overridden->getCanonicalDecl()); +else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate()) + Canonical = + cast(Primary->getTemplatedDecl()->getCanonicalDecl()); if (Canonical != ND) return Canonical; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fc976ce3a33d5..e86786cfb301a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -343,7 +343,8 @@ Changes in existing checks ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian Prefix when configured to `LowerCase`. Added support for renaming designated - initializers. Added support for renaming macro arguments. + initializers. Added support for renaming macro arguments. Fixed renaming + conflicts arising from out-of-line member function template definitions. - Improved :doc:`readability-implicit-bool-conversion ` check to provide diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp new file mode 100644 index 0..f807875e27698 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp @@ -0,0 +1,30 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -std=c++20 \ +// RUN: --config='{CheckOptions: { \ +// RUN: readability-identifier-naming.MethodCase: CamelCase, \ +// RUN: }}' + +namespace SomeNamespace { +namespace Inner { + +class SomeClass { +public: +template +int someMethod(); +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for method 'someMethod' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int SomeMethod(); +}; +template +int SomeClass::someMethod() { +// CHECK-FIXES: {{^}}int SomeClass::SomeMethod() { +return 5; +} + +} // namespace Inner + +void someFunc() { +Inner::SomeClass S; +S.someMethod(); +// CHECK-FIXES: {{^}}S.SomeMethod(); +} + +} // namespace SomeNamespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
revane wrote: @PiotrZSL Finally fixing renaming of out-of-line template member functions. https://github.com/llvm/llvm-project/pull/91954 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/91954 >From ffcc0bfc29b577fd727bc00a912e4c0eb515628a Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Mon, 15 Apr 2024 09:38:48 -0400 Subject: [PATCH] [clang-tidy] Rename out-of-line function definitions Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration. --- .../utils/RenamerClangTidyCheck.cpp | 3 ++ clang-tools-extra/docs/ReleaseNotes.rst | 3 +- .../readability/identifier-naming-ool.cpp | 30 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index e811f5519de2c..88e4886cd0df9 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -123,6 +123,9 @@ static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { if (const auto *Method = dyn_cast(ND)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Canonical = cast(Overridden->getCanonicalDecl()); +else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate()) + if (const FunctionDecl *TemplatedDecl = Primary->getTemplatedDecl()) +Canonical = cast(TemplatedDecl->getCanonicalDecl()); if (Canonical != ND) return Canonical; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fc976ce3a33d5..e86786cfb301a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -343,7 +343,8 @@ Changes in existing checks ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian Prefix when configured to `LowerCase`. Added support for renaming designated - initializers. Added support for renaming macro arguments. + initializers. Added support for renaming macro arguments. Fixed renaming + conflicts arising from out-of-line member function template definitions. - Improved :doc:`readability-implicit-bool-conversion ` check to provide diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp new file mode 100644 index 0..f807875e27698 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-ool.cpp @@ -0,0 +1,30 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -std=c++20 \ +// RUN: --config='{CheckOptions: { \ +// RUN: readability-identifier-naming.MethodCase: CamelCase, \ +// RUN: }}' + +namespace SomeNamespace { +namespace Inner { + +class SomeClass { +public: +template +int someMethod(); +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for method 'someMethod' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int SomeMethod(); +}; +template +int SomeClass::someMethod() { +// CHECK-FIXES: {{^}}int SomeClass::SomeMethod() { +return 5; +} + +} // namespace Inner + +void someFunc() { +Inner::SomeClass S; +S.someMethod(); +// CHECK-FIXES: {{^}}S.SomeMethod(); +} + +} // namespace SomeNamespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
@@ -123,6 +123,9 @@ static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { if (const auto *Method = dyn_cast(ND)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Canonical = cast(Overridden->getCanonicalDecl()); +else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate()) + Canonical = + cast(Primary->getTemplatedDecl()->getCanonicalDecl()); revane wrote: Done. https://github.com/llvm/llvm-project/pull/91954 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
revane wrote: @PiotrZSL If everything looks good could you merge this PR for me? https://github.com/llvm/llvm-project/pull/91954 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/91954 >From 5028579d9eb06eb3f1d27f984c0348884334e136 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Mon, 15 Apr 2024 09:38:48 -0400 Subject: [PATCH] [clang-tidy] Rename out-of-line function definitions Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration. --- .../utils/RenamerClangTidyCheck.cpp | 3 ++ clang-tools-extra/docs/ReleaseNotes.rst | 3 +- .../identifier-naming-outofline.cpp | 30 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-outofline.cpp diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index e811f5519de2c..88e4886cd0df9 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -123,6 +123,9 @@ static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) { if (const auto *Method = dyn_cast(ND)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Canonical = cast(Overridden->getCanonicalDecl()); +else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate()) + if (const FunctionDecl *TemplatedDecl = Primary->getTemplatedDecl()) +Canonical = cast(TemplatedDecl->getCanonicalDecl()); if (Canonical != ND) return Canonical; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fc976ce3a33d5..e86786cfb301a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -343,7 +343,8 @@ Changes in existing checks ` check in `GetConfigPerFile` mode by resolving symbolic links to header files. Fixed handling of Hungarian Prefix when configured to `LowerCase`. Added support for renaming designated - initializers. Added support for renaming macro arguments. + initializers. Added support for renaming macro arguments. Fixed renaming + conflicts arising from out-of-line member function template definitions. - Improved :doc:`readability-implicit-bool-conversion ` check to provide diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-outofline.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-outofline.cpp new file mode 100644 index 0..f807875e27698 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-outofline.cpp @@ -0,0 +1,30 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -std=c++20 \ +// RUN: --config='{CheckOptions: { \ +// RUN: readability-identifier-naming.MethodCase: CamelCase, \ +// RUN: }}' + +namespace SomeNamespace { +namespace Inner { + +class SomeClass { +public: +template +int someMethod(); +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for method 'someMethod' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int SomeMethod(); +}; +template +int SomeClass::someMethod() { +// CHECK-FIXES: {{^}}int SomeClass::SomeMethod() { +return 5; +} + +} // namespace Inner + +void someFunc() { +Inner::SomeClass S; +S.someMethod(); +// CHECK-FIXES: {{^}}S.SomeMethod(); +} + +} // namespace SomeNamespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Rename out-of-line function definitions (PR #91954)
revane wrote: It's not too late until it's submitted. I renamed the file as requested. https://github.com/llvm/llvm-project/pull/91954 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits