[clang-tools-extra] r220826 - [clang-tidy] Added -system-headers option.
Alexander Kornienko
alexfh at google.com
Tue Oct 28 15:16:13 PDT 2014
Author: alexfh
Date: Tue Oct 28 17:16:13 2014
New Revision: 220826
URL: http://llvm.org/viewvc/llvm-project?rev=220826&view=rev
Log:
[clang-tidy] Added -system-headers option.
Added -system-headers option to allow display of warnings from system headers.
This is needed for testing libcxx, for example.
Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/system-header.h
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
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=220826&r1=220825&r2=220826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Tue Oct 28 17:16:13 2014
@@ -367,7 +367,8 @@ void ClangTidyDiagnosticConsumer::checkF
}
const SourceManager &Sources = Diags->getSourceManager();
- if (Sources.isInSystemHeader(Location))
+ if (!*Context.getOptions().SystemHeaders &&
+ Sources.isInSystemHeader(Location))
return;
// FIXME: We start with a conservative approach here, but the actual type of
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp?rev=220826&r1=220825&r2=220826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp Tue Oct 28 17:16:13 2014
@@ -101,6 +101,7 @@ ClangTidyOptions ClangTidyOptions::getDe
ClangTidyOptions Options;
Options.Checks = "";
Options.HeaderFilterRegex = "";
+ Options.SystemHeaders = false;
Options.AnalyzeTemporaryDtors = false;
Options.User = llvm::None;
for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
@@ -122,6 +123,8 @@ ClangTidyOptions::mergeWith(const ClangT
if (Other.HeaderFilterRegex)
Result.HeaderFilterRegex = Other.HeaderFilterRegex;
+ if (Other.SystemHeaders)
+ Result.SystemHeaders = Other.SystemHeaders;
if (Other.AnalyzeTemporaryDtors)
Result.AnalyzeTemporaryDtors = Other.AnalyzeTemporaryDtors;
if (Other.User)
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h?rev=220826&r1=220825&r2=220826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h Tue Oct 28 17:16:13 2014
@@ -66,6 +66,9 @@ struct ClangTidyOptions {
/// main files will always be displayed.
llvm::Optional<std::string> HeaderFilterRegex;
+ /// \brief Output warnings from system headers matching \c HeaderFilterRegex.
+ llvm::Optional<bool> SystemHeaders;
+
/// \brief Turns on temporary destructor-based analysis.
llvm::Optional<bool> AnalyzeTemporaryDtors;
Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=220826&r1=220825&r2=220826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Tue Oct 28 17:16:13 2014
@@ -63,6 +63,10 @@ HeaderFilter("header-filter",
".clang-tidy file."),
cl::init(""), cl::cat(ClangTidyCategory));
+static cl::opt<bool>
+ SystemHeaders("system-headers",
+ cl::desc("Display the errors from system headers"),
+ cl::init(false), cl::cat(ClangTidyCategory));
static cl::opt<std::string>
LineFilter("line-filter",
cl::desc("List of files with line ranges to filter the\n"
@@ -198,6 +202,7 @@ std::unique_ptr<ClangTidyOptionsProvider
ClangTidyOptions DefaultOptions;
DefaultOptions.Checks = DefaultChecks;
DefaultOptions.HeaderFilterRegex = HeaderFilter;
+ DefaultOptions.SystemHeaders = SystemHeaders;
DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
// USERNAME is used on Windows.
@@ -209,6 +214,8 @@ std::unique_ptr<ClangTidyOptionsProvider
OverrideOptions.Checks = Checks;
if (HeaderFilter.getNumOccurrences() > 0)
OverrideOptions.HeaderFilterRegex = HeaderFilter;
+ if (SystemHeaders.getNumOccurrences() > 0)
+ OverrideOptions.SystemHeaders = SystemHeaders;
if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/system-header.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/system-header.h?rev=220826&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/system-header.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/system/system-header.h Tue Oct 28 17:16:13 2014
@@ -0,0 +1 @@
+class A0 { A0(int); };
Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=220826&r1=220825&r2=220826&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Tue Oct 28 17:16:13 2014
@@ -1,29 +1,42 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK2 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK3 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s
#include "header1.h"
// CHECK-NOT: warning:
// CHECK2: header1.h:1:12: warning: Single-argument constructors must be explicit [google-explicit-constructor]
// CHECK3-NOT: warning:
+// CHECK4: header1.h:1:12: warning: Single-argument constructors
#include "header2.h"
// CHECK-NOT: warning:
-// CHECK2: header2.h:1:12: warning: Single-argument constructors {{.*}}
-// CHECK3: header2.h:1:12: warning: Single-argument constructors {{.*}}
+// CHECK2: header2.h:1:12: warning: Single-argument constructors
+// CHECK3: header2.h:1:12: warning: Single-argument constructors
+// CHECK4: header2.h:1:12: warning: Single-argument constructors
+
+#include <system-header.h>
+// CHECK-NOT: warning:
+// CHECK2-NOT: warning:
+// CHECK3-NOT: warning:
+// CHECK4: system-header.h:1:12: warning: Single-argument constructors
class A { A(int); };
-// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors {{.*}}
-// CHECK2: :[[@LINE-2]]:11: warning: Single-argument constructors {{.*}}
-// CHECK3: :[[@LINE-3]]:11: warning: Single-argument constructors {{.*}}
+// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors
+// CHECK2: :[[@LINE-2]]:11: warning: Single-argument constructors
+// CHECK3: :[[@LINE-3]]:11: warning: Single-argument constructors
+// CHECK4: :[[@LINE-4]]:11: warning: Single-argument constructors
// CHECK-NOT: warning:
// CHECK2-NOT: warning:
// CHECK3-NOT: warning:
+// CHECK4-NOT: warning:
-// CHECK: Suppressed 2 warnings (2 in non-user code)
+// CHECK: Suppressed 3 warnings (3 in non-user code)
// CHECK: Use -header-filter='.*' to display errors from all non-system headers.
-// CHECK2-NOT: Suppressed {{.*}} warnings
-// CHECK2-NOT: Use -header-filter='.*' {{.*}}
-// CHECK3: Suppressed 1 warnings (1 in non-user code)
+// CHECK2: Suppressed 1 warnings (1 in non-user code)
+// CHECK2: Use -header-filter='.*' {{.*}}
+// CHECK3: Suppressed 2 warnings (2 in non-user code)
// CHECK3: Use -header-filter='.*' {{.*}}
+// CHECK4-NOT: Suppressed {{.*}} warnings
+// CHECK4-NOT: Use -header-filter='.*' {{.*}}
More information about the cfe-commits
mailing list