Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -481,6 +481,16 @@ ClangTool Tool(Compilations, InputFiles, std::make_shared(), BaseFS); + // Add __clang_analyzer__ macro definition for compatibility with the clang + // static analyzer. + ArgumentsAdjuster ClangTidyMacroDefinitionInserter = + [&Context](const CommandLineArguments &Args, StringRef Filename) { + ClangTidyOptions Opts = Context.getOptionsForFile(Filename); + CommandLineArguments AdjustedArgs = Args; + AdjustedArgs.emplace_back("-D__clang_analyzer__"); + return AdjustedArgs; + }; + // Add extra arguments passed by the clang-tidy command-line. ArgumentsAdjuster PerFileExtraArgumentsInserter = [&Context](const CommandLineArguments &Args, StringRef Filename) { @@ -515,6 +525,7 @@ return AdjustedArgs; }; + Tool.appendArgumentsAdjuster(ClangTidyMacroDefinitionInserter); Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter); Tool.appendArgumentsAdjuster(PluginArgumentsRemover); if (Profile) Index: test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp =================================================================== --- /dev/null +++ test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp @@ -0,0 +1,8 @@ +// RUN: %check_clang_tidy %s * %t + +#if defined(__clang_analyzer__) +#warning __clang_analyzer__ is defined +#endif +// CHECK-MESSAGES: :[[@LINE-2]]:2: warning: __clang_analyzer__ is defined [clang-diagnostic-#warnings] + +