-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-tidy] support query based custom check #131804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a686695
origin pr
DeNiCoN 421b26b
Revert "origin pr"
HerrCai0907 6fa8f7e
impl option
HerrCai0907 6ab7149
impl
HerrCai0907 db6b315
extend func
HerrCai0907 dba8a8c
wip
HerrCai0907 0df6f7e
test
HerrCai0907 5bb2c6c
doc
HerrCai0907 64c45dc
fix comment
HerrCai0907 b650594
Update clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
HerrCai0907 b56c07c
fix review
HerrCai0907 5bbf53d
Merge branch 'main' into users/ccc/clang-tidy/query-check
HerrCai0907 b43991f
Merge remote-tracking branch 'origin/users/ccc/clang-tidy/query-check…
HerrCai0907 b2cecb8
add CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS cmake config
HerrCai0907 71eeaa1
Merge branch 'main' of https://github.com/llvm/llvm-project into user…
HerrCai0907 8be412c
remove ERROR level
HerrCai0907 1367f0b
fix typo
HerrCai0907 595e0a6
test, doc
HerrCai0907 190ad52
typo
HerrCai0907 5500699
fix review
HerrCai0907 4ce48a5
Apply suggestions from code review
HerrCai0907 fd15b05
Apply suggestions from code review
HerrCai0907 73dfc6e
Merge branch 'main' into users/ccc/clang-tidy/query-check
HerrCai0907 dce9682
Merge remote-tracking branch 'origin/main' into users/ccc/clang-tidy/…
HerrCai0907 b534fe9
add --enable-experimental-custom-checks
HerrCai0907 a373c55
rename
HerrCai0907 0a99d0c
format
HerrCai0907 9c1828f
Merge remote-tracking branch 'origin/main' into users/ccc/clang-tidy/…
HerrCai0907 2a3e0f1
doc
HerrCai0907 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
if(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS) | ||
set(LLVM_LINK_COMPONENTS | ||
support | ||
) | ||
|
||
add_clang_library(clangTidyCustomModule STATIC | ||
CustomTidyModule.cpp | ||
QueryCheck.cpp | ||
|
||
LINK_LIBS | ||
clangTidy | ||
clangTidyUtils | ||
|
||
DEPENDS | ||
ClangDriverOptions | ||
) | ||
|
||
clang_target_link_libraries(clangTidyCustomModule | ||
PRIVATE | ||
clangQuery | ||
) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "../ClangTidy.h" | ||
#include "../ClangTidyModule.h" | ||
#include "../ClangTidyModuleRegistry.h" | ||
#include "../ClangTidyOptions.h" | ||
#include "QueryCheck.h" | ||
#include "llvm/ADT/SmallSet.h" | ||
#include "llvm/ADT/SmallString.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <memory> | ||
|
||
namespace clang::tidy { | ||
namespace custom { | ||
|
||
class CustomModule : public ClangTidyModule { | ||
public: | ||
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {} | ||
}; | ||
|
||
// We need to register the checks more flexibly than builtin modules. The checks | ||
// will changed dynamically when switching to different source file. | ||
extern void registerCustomChecks(const ClangTidyOptions &Options, | ||
ClangTidyCheckFactories &Factories) { | ||
static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{}; | ||
if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty()) | ||
return; | ||
for (const llvm::SmallString<32> &Name : CustomCheckNames) | ||
Factories.eraseCheck(Name); | ||
for (const ClangTidyOptions::CustomCheckValue &V : | ||
Options.CustomChecks.value()) { | ||
llvm::SmallString<32> Name = llvm::StringRef{"custom-" + V.Name}; | ||
Factories.registerCheckFactory( | ||
// add custom- prefix to avoid conflicts with builtin checks | ||
Name, [&V](llvm::StringRef Name, ClangTidyContext *Context) { | ||
return std::make_unique<custom::QueryCheck>(Name, V, Context); | ||
}); | ||
CustomCheckNames.insert(std::move(Name)); | ||
} | ||
} | ||
|
||
} // namespace custom | ||
|
||
// Register the CustomTidyModule using this statically initialized variable. | ||
static ClangTidyModuleRegistry::Add<custom::CustomModule> | ||
X("custom-module", "Adds custom query lint checks."); | ||
|
||
// This anchor is used to force the linker to link in the generated object file | ||
// and thus register the AlteraModule. | ||
volatile int CustomModuleAnchorSource = 0; // NOLINT (misc-use-internal-linkage) | ||
|
||
} // namespace clang::tidy |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.