[clang-tools-extra] r210044 - Never filter-out compile errors in clang-tidy, display them as errors.

Alexander Kornienko alexfh at google.com
Mon Jun 2 13:44:32 PDT 2014


Author: alexfh
Date: Mon Jun  2 15:44:32 2014
New Revision: 210044

URL: http://llvm.org/viewvc/llvm-project?rev=210044&view=rev
Log:
Never filter-out compile errors in clang-tidy, display them as errors.

Summary:
No filters should affect the display of errors. Fixed a few tests,
which had compile errors.

We need to think what we should do with mapped errors (-Werror).

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D3982

Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
    clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
    clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
    clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Mon Jun  2 15:44:32 2014
@@ -336,8 +336,9 @@ ClangTidyStats runClangTidy(const ClangT
 void handleErrors(const std::vector<ClangTidyError> &Errors, bool Fix) {
   ErrorReporter Reporter(Fix);
   for (const ClangTidyError &Error : Errors) {
-    Reporter.reportDiagnostic(Error.Message, DiagnosticsEngine::Warning,
-                              &Error.Fix);
+    Reporter.reportDiagnostic(
+        Error.Message, static_cast<DiagnosticsEngine::Level>(Error.DiagLevel),
+        &Error.Fix);
     for (const ClangTidyMessage &Note : Error.Notes)
       Reporter.reportDiagnostic(Note, DiagnosticsEngine::Note);
   }

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Mon Jun  2 15:44:32 2014
@@ -109,7 +109,9 @@ ClangTidyMessage::ClangTidyMessage(Strin
   FileOffset = Sources.getFileOffset(Loc);
 }
 
-ClangTidyError::ClangTidyError(StringRef CheckName) : CheckName(CheckName) {}
+ClangTidyError::ClangTidyError(StringRef CheckName,
+                               ClangTidyError::Level DiagLevel)
+    : CheckName(CheckName), DiagLevel(DiagLevel) {}
 
 // Returns true if GlobList starts with the negative indicator ('-'), removes it
 // from the GlobList.
@@ -214,7 +216,8 @@ ClangTidyDiagnosticConsumer::ClangTidyDi
 void ClangTidyDiagnosticConsumer::finalizeLastError() {
   if (!Errors.empty()) {
     ClangTidyError &Error = Errors.back();
-    if (!Context.getChecksFilter().isCheckEnabled(Error.CheckName)) {
+    if (!Context.getChecksFilter().isCheckEnabled(Error.CheckName) &&
+        Error.DiagLevel != ClangTidyError::Error) {
       ++Context.Stats.ErrorsIgnoredCheckFilter;
       Errors.pop_back();
     } else if (!LastErrorRelatesToUserCode) {
@@ -246,7 +249,14 @@ void ClangTidyDiagnosticConsumer::Handle
                                 ? ("clang-diagnostic-" + WarningOption).str()
                                 : Context.getCheckName(Info.getID()).str();
 
-    Errors.push_back(ClangTidyError(CheckName));
+    ClangTidyError::Level Level = ClangTidyError::Warning;
+    if (DiagLevel == DiagnosticsEngine::Error ||
+        DiagLevel == DiagnosticsEngine::Fatal) {
+      Level = ClangTidyError::Error;
+      LastErrorRelatesToUserCode = true;
+      LastErrorPassesLineFilter = true;
+    }
+    Errors.push_back(ClangTidyError(CheckName, Level));
   }
 
   // FIXME: Provide correct LangOptions for each file.

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Mon Jun  2 15:44:32 2014
@@ -49,12 +49,19 @@ struct ClangTidyMessage {
 ///
 /// FIXME: Make Diagnostics flexible enough to support this directly.
 struct ClangTidyError {
-  ClangTidyError(StringRef CheckName);
+  enum Level {
+    Warning = DiagnosticsEngine::Warning,
+    Error = DiagnosticsEngine::Error
+  };
+
+  ClangTidyError(StringRef CheckName, Level DiagLevel);
 
   std::string CheckName;
   ClangTidyMessage Message;
   tooling::Replacements Fix;
   SmallVector<ClangTidyMessage, 1> Notes;
+
+  Level DiagLevel;
 };
 
 /// \brief Filters checks by name.

Modified: clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp Mon Jun  2 15:44:32 2014
@@ -1,12 +1,12 @@
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s
 
 template<typename T>
-class A { A(T); };
-// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]
+struct A { A(T); };
+// CHECK: :[[@LINE-1]]:12: warning: Single-argument constructors must be explicit [google-explicit-constructor]
 // CHECK-NOT: warning:
 
 
 void f() {
-  A<int> a;
-  A<double> b;
+  A<int> a(0);
+  A<double> b(0);
 }

Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Mon Jun  2 15:44:32 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
+// RUN: clang-tidy -checks='-*,misc-use-override' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
 // RUN: clang-tidy -checks='google-explicit-constructor' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s
 // RUN: clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s
 // RUN: clang-tidy -checks='-*,misc-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
@@ -7,8 +7,8 @@
 // CHECK2-NOT: warning
 // CHECK3-NOT: warning
 
-// CHECK1: warning: error reading '{{.*}}.nonexistent.cpp'
-// CHECK2: warning: unknown argument: '-fan-unknown-option'
+// CHECK1: error: error reading '{{.*}}.nonexistent.cpp'
+// CHECK2: error: unknown argument: '-fan-unknown-option'
 
 // CHECK2: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' changes value
 // CHECK3: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value

Modified: clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp?rev=210044&r1=210043&r2=210044&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp Mon Jun  2 15:44:32 2014
@@ -6,20 +6,21 @@
 namespace std {
 
 template <typename T>
-class unique_ptr {
+struct unique_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
 };
 
 template <typename T>
-class shared_ptr {
+struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
 };
 
 }  // namespace std
+#define NULL __null
 
 struct int_ptr {
   int* get();





More information about the cfe-commits mailing list