-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[analyzer] Prettify checker registration and unittest code #147797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
fc638a1
1e29385
43a3430
4c5c619
0709492
5ea4670
073f056
211794e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -38,29 +38,29 @@ | |||||||
// function clang_registerCheckers. For example: | ||||||||
// | ||||||||
// extern "C" | ||||||||
// void clang_registerCheckers (CheckerRegistry ®istry) { | ||||||||
// registry.addChecker<MainCallChecker>("example.MainCallChecker", | ||||||||
// "Disallows calls to functions called main"); | ||||||||
// void clang_registerCheckers(CheckerRegistry &Registry) { | ||||||||
// Registry.addChecker<MainCallChecker>( | ||||||||
// "example.MainCallChecker", | ||||||||
// "Disallows calls to functions called main"); | ||||||||
// } | ||||||||
// | ||||||||
// The first method argument is the full name of the checker, including its | ||||||||
// enclosing package. By convention, the registered name of a checker is the | ||||||||
// name of the associated class (the template argument). | ||||||||
// The second method argument is a short human-readable description of the | ||||||||
// checker. | ||||||||
// The first argument of this templated method is the full name of the checker | ||||||||
// (including its package), while the second argument is a short description | ||||||||
// that is printed by `-analyzer-checker-help`. | ||||||||
// | ||||||||
// The clang_registerCheckers function may add any number of checkers to the | ||||||||
// registry. If any checkers require additional initialization, use the three- | ||||||||
// argument form of CheckerRegistry::addChecker. | ||||||||
// A plugin may register several separate checkers by calling `addChecker()` | ||||||||
// multiple times. If a checker requires custom registration functions (e.g. | ||||||||
// checker option handling) use the non-templated variant of `addChecker` that | ||||||||
// takes two callback functions as the first two parameters. | ||||||||
// | ||||||||
// To load a checker plugin, specify the full path to the dynamic library as | ||||||||
// the argument to the -load option in the cc1 frontend. You can then enable | ||||||||
// your custom checker using the -analyzer-checker: | ||||||||
// | ||||||||
// clang -cc1 -load </path/to/plugin.dylib> -analyze | ||||||||
// -analyzer-checker=<example.MainCallChecker> | ||||||||
// clang -cc1 -load /path/to/plugin.dylib -analyze | ||||||||
// -analyzer-checker=example.MainCallChecker | ||||||||
// | ||||||||
// For a complete working example, see examples/analyzer-plugin. | ||||||||
// For complete examples, see clang/lib/Analysis/plugins/SampleAnalyzer | ||||||||
|
||||||||
#ifndef CLANG_ANALYZER_API_VERSION_STRING | ||||||||
// FIXME: The Clang version string is not particularly granular; | ||||||||
|
@@ -112,26 +112,35 @@ class CheckerRegistry { | |||||||
return true; | ||||||||
} | ||||||||
|
||||||||
public: | ||||||||
/// Adds a checker to the registry. Use this non-templated overload when your | ||||||||
/// checker requires custom initialization. | ||||||||
void addChecker(RegisterCheckerFn Fn, ShouldRegisterFunction sfn, | ||||||||
/// Adds a checker to the registry. This private, most general variant is | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could you make the |
||||||||
/// intended for loading the checker definitions from `Checkers.td`. | ||||||||
/// FIXME: The checker registry should not bother with loading `DocsUri` | ||||||||
/// because it is (as of now) never queried from the checker registry. | ||||||||
void addChecker(RegisterCheckerFn Fn, ShouldRegisterFunction Sfn, | ||||||||
StringRef FullName, StringRef Desc, StringRef DocsUri, | ||||||||
bool IsHidden); | ||||||||
|
||||||||
/// Adds a checker to the registry. Use this templated overload when your | ||||||||
/// checker does not require any custom initialization. | ||||||||
/// This function isn't really needed and probably causes more headaches than | ||||||||
/// the tiny convenience that it provides, but external plugins might use it, | ||||||||
/// and there isn't a strong incentive to remove it. | ||||||||
public: | ||||||||
/// Adds a checker to the registry. Use this for a checker defined in a | ||||||||
/// plugin if it requires custom registration functions. | ||||||||
void addChecker(RegisterCheckerFn Fn, ShouldRegisterFunction Sfn, | ||||||||
StringRef FullName, StringRef Desc, bool IsHidden = false) { | ||||||||
addChecker(Fn, Sfn, FullName, Desc, "NoDocsUri", IsHidden); | ||||||||
} | ||||||||
|
||||||||
/// Adds a checker to the registry. Use this for a checker defined in a | ||||||||
/// plugin if it doesn't require custom registration functions. | ||||||||
template <class T> | ||||||||
void addChecker(StringRef FullName, StringRef Desc, StringRef DocsUri, | ||||||||
bool IsHidden = false) { | ||||||||
// Avoid MSVC's Compiler Error C2276: | ||||||||
// http://msdn.microsoft.com/en-us/library/850cstw1(v=VS.80).aspx | ||||||||
void addChecker(StringRef FullName, StringRef Desc, bool IsHidden = false) { | ||||||||
addChecker(&CheckerRegistry::initializeManager<CheckerManager, T>, | ||||||||
&CheckerRegistry::returnTrue<T>, FullName, Desc, DocsUri, | ||||||||
IsHidden); | ||||||||
&CheckerRegistry::returnTrue<T>, FullName, Desc, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a random comment: I never understood why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I, too, have no idea 🙃 and I asked @Szelethus who added the template parameter in 2020, but he doesn't remember why was it added. The projects can be compiled and linked without the template parameter, so I decided to remove it in 4c5c619 |
||||||||
/*IsHidden=*/IsHidden); | ||||||||
} | ||||||||
|
||||||||
/// Add a mock checker to the registry for testing purposes, without | ||||||||
/// specifying metadata that is not relevant in simple tests. | ||||||||
template <class T> void addMockChecker(StringRef FullName) { | ||||||||
addChecker<T>(FullName, "MockCheckerDescription"); | ||||||||
} | ||||||||
|
||||||||
/// Makes the checker with the full name \p fullName depend on the checker | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.