Search code examples
c++clang++llvm-clang

Clang Diagnostics, how to ignore compiler specific extensions


My production code is compiled on a proprietary compiler with some language extensions, for example:

__even_in_range(TA2IV, TA2IV_TAIFG);

But I am using clang as code analysis tool, and getting this error error: use of undeclared identifier '__even_in_range'. There are few more language extensions that produce similar behavior. Is there any way to ask clang to ignore certain identifiers?

EDIT: Both of the comments guided me towards define solution, so I added these compiler options to the code analysis package ( I use https://github.com/lvzixun/Clang-Complete package).

  1. -D __even_in_range(y,x)=y
  2. -D __interrupt=

This way none of my sources are influenced by the static analysis tool

Thanks...


Solution

  • You can use the predefined macro __clang_analyzer__ to identify that the analyzer is being run, and just #define out those extensions in that case:

    #ifdef __clang_analyzer__
    #define __even_in_range(...)
    ...
    #endif
    

    Details here, along with other ideas to get rid of false positives.