Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 877
Gawain Avatar asked Jul 21 '15 14:07

Gawain


People also ask

How do I disable clang-tidy checks?

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.

What is clang diagnostic?

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.

Does clang define __ GNUC __?

(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.

Should I use clang or GCC?

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.


1 Answers

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
like image 109
LVK Avatar answered Oct 20 '22 06:10

LVK