Gawain
Gawain

Reputation: 71

Disable Clang Tool diagnostics

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.

Upvotes: 5

Views: 2250

Answers (1)

LVK
LVK

Reputation: 337

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

Upvotes: 6

Related Questions