[PATCH] D46325: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer. 2nd try.

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 3 11:31:04 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL331474: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility… (authored by zinovy.nis, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D46325?vs=145059&id=145060#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46325

Files:
  clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
  clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp


Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -524,6 +524,18 @@
     ActionFactory(ClangTidyContext &Context) : ConsumerFactory(Context) {}
     FrontendAction *create() override { return new Action(&ConsumerFactory); }
 
+    bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
+                       FileManager *Files,
+                       std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+                       DiagnosticConsumer *DiagConsumer) override {
+      // Explicitly set ProgramAction to RunAnalysis to make the preprocessor
+      // define __clang_analyzer__ macro. The frontend analyzer action will not
+      // be called here.
+      Invocation->getFrontendOpts().ProgramAction = frontend::RunAnalysis;
+      return FrontendActionFactory::runInvocation(
+          Invocation, Files, PCHContainerOps, DiagConsumer);
+    }
+
   private:
     class Action : public ASTFrontendAction {
     public:
Index: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+#if !defined(__clang_analyzer__)
+#error __clang_analyzer__ is not defined
+#endif
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+#if !defined(__clang_analyzer__)
+#error __clang_analyzer__ is not defined
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46325.145060.patch
Type: text/x-patch
Size: 1779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180503/73355bf0/attachment.bin>


More information about the cfe-commits mailing list