[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
Tue May 1 11:18:37 PDT 2018
zinovy.nis created this revision.
zinovy.nis added reviewers: george.karpenkov, alexfh, hokein.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, a.sidorin, xazax.hun.
This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered as [[no-return]], and a lot of false-positive warnings about nullptr dereferenced are emitted.
This patch fixes the issue.
This revision is the second version of https://reviews.llvm.org/D44906.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D46325
Files:
clang-tidy/ClangTidy.cpp
test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
Index: test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
===================================================================
--- test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
+++ test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+#if !defined(__clang_analyzer__)
+#error __clang_analyzer__ is not defined
+#endif
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -529,6 +529,15 @@
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 {
+ Invocation->getFrontendOpts().ProgramAction = frontend::RunAnalysis;
+ return FrontendActionFactory::runInvocation(
+ Invocation, Files, PCHContainerOps, DiagConsumer);
+ }
+
private:
class Action : public ASTFrontendAction {
public:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46325.144757.patch
Type: text/x-patch
Size: 1293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180501/0bd63809/attachment.bin>
More information about the cfe-commits
mailing list