Disable Clang Tool Diagnostics

This will be a general question. I am currently writing a tool for clang

which is related to bypass AST. So I have frontendaction

to create ASTConsumer

, which, in addition, has RecursiveASTVistor

. I am calling Tool.run()

to perform my action. It works fine, but clang by default outputs all warnings and errors in the repo that I am trying to parse. Is there anyway I can turn off clang diagnostics? I know that when compiling with clang, the option -w

turns off diagnostics. But how do we do it for the instrument? By the way, my instrument is in/llvm/tools/clang/tools/extra/mytool

Thank.

+3


source to share


1 answer


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 a -w

parameter to your tool after --

on the command line to ignore warnings (error messages won't be canceled, of course):

mytool.exe test.cpp -- -w

      

+3


source







All Articles