[clang-tools-extra] r244745 - Lazily initialize HeaderFilter in ClangTidyDiagnosticConsumer. This
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 06:16:41 PDT 2015
Author: djasper
Date: Wed Aug 12 08:16:41 2015
New Revision: 244745
URL: http://llvm.org/viewvc/llvm-project?rev=244745&view=rev
Log:
Lazily initialize HeaderFilter in ClangTidyDiagnosticConsumer. This
removes a corner case in tests that don't set the diagnostic consumer.
In tests, it is good, not to set the diagnostic consumer so that Clang's
parsing diagnostics are still displayed in the test output and only
ClangTidy's output is analyzed differently.
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
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=244745&r1=244744&r2=244745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Wed Aug 12 08:16:41 2015
@@ -336,13 +336,6 @@ void ClangTidyDiagnosticConsumer::Handle
checkFilters(Info.getLocation());
}
-void ClangTidyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
- const Preprocessor *PP) {
- // Before the first translation unit we don't need HeaderFilter, as we
- // shouldn't get valid source locations in diagnostics.
- HeaderFilter.reset(new llvm::Regex(*Context.getOptions().HeaderFilterRegex));
-}
-
bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
unsigned LineNumber) const {
if (Context.getGlobalOptions().LineFilter.empty())
@@ -389,17 +382,22 @@ void ClangTidyDiagnosticConsumer::checkF
}
StringRef FileName(File->getName());
- assert(LastErrorRelatesToUserCode || Sources.isInMainFile(Location) ||
- HeaderFilter != nullptr);
LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
- HeaderFilter->match(FileName);
+ getHeaderFilter()->match(FileName);
unsigned LineNumber = Sources.getExpansionLineNumber(Location);
LastErrorPassesLineFilter =
LastErrorPassesLineFilter || passesLineFilter(FileName, LineNumber);
}
+llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
+ if (!HeaderFilter)
+ HeaderFilter.reset(
+ new llvm::Regex(*Context.getOptions().HeaderFilterRegex));
+ return HeaderFilter.get();
+}
+
namespace {
struct LessClangTidyError {
bool operator()(const ClangTidyError *LHS, const ClangTidyError *RHS) const {
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=244745&r1=244744&r2=244745&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Wed Aug 12 08:16:41 2015
@@ -220,16 +220,16 @@ public:
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info) override;
- /// \brief Sets \c HeaderFilter to the value configured for this file.
- void BeginSourceFile(const LangOptions &LangOpts,
- const Preprocessor *PP) override;
-
/// \brief Flushes the internal diagnostics buffer to the ClangTidyContext.
void finish() override;
private:
void finalizeLastError();
+ /// \brief Returns the \c HeaderFilter constructed for the options set in the
+ /// context.
+ llvm::Regex* getHeaderFilter();
+
/// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
/// according to the diagnostic \p Location.
void checkFilters(SourceLocation Location);
More information about the cfe-commits
mailing list