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. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@244745 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
178caf7f76
Коммит
d8db79cb34
|
@ -336,13 +336,6 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
|
|||
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::checkFilters(SourceLocation Location) {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче