This will be a general question. I am currently writing a tool for clang
which is related to AST traversal. So I have a frontendaction
to create an ASTConsumer
which, further, has a RecursiveASTVistor
. I call Tool.run()
to execute my action. It runs fine but clang by default prints out all the warnings and errors in the repo I try to analyze. Is there anyway I can disable clang diagnostics? I know that when we compile with clang, the -w
option all disable diagnostics. But How do we do that for a tool? By the way, my tool resides in /llvm/tools/clang/tools/extra/mytool
Thanks.
If you must enable or disable particular checks, use the clang-tidy command-line format in your . clang-tidy files. The command-line format specifies a comma-separated list of positive and negative globs: positive globs add subsets of checks, and negative globs (prefixed with - ) remove subsets of checks.
Allows you to suppress, enable, or change the severity of specific diagnostic messages from within your code. For example, you can suppress a particular diagnostic message when compiling one specific function.
(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.
Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.
You can use IgnoringDiagConsumer which suppresses all diagnostic messages:
class MyFrontendAction : public ASTFrontendAction
{
public:
MyFrontendAction() {}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
{
CI.getDiagnostics().setClient(new IgnoringDiagConsumer());
return llvm::make_unique<MyASTConsumer>();
}
};
Or you can implement your own DiagnosticConsumer to handle diagnostics.
Another option is to pass -w
option to your tool after --
at command line to ignore warnings (error messages will not be suppressed, of course):
mytool.exe test.cpp -- -w
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With