Skip to content

Commit 8d712f4

Browse files
committed
[clang-tidy] Fix ClangTidyDiagnosticConsumer
1 parent 26d1aa7 commit 8d712f4

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,20 @@ static bool parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
239239
void ClangTidyContext::setCurrentFile(StringRef File) {
240240
CurrentFile = std::string(File);
241241
CurrentOptions = getOptionsForFile(CurrentFile);
242-
CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
243-
WarningAsErrorFilter =
244-
std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
245-
if (!parseFileExtensions(*getOptions().HeaderFileExtensions,
242+
CheckFilter = std::make_unique<CachedGlobList>(
243+
getOptions().Checks ? StringRef(*getOptions().Checks) : StringRef(""));
244+
WarningAsErrorFilter = std::make_unique<CachedGlobList>(
245+
getOptions().WarningsAsErrors ? StringRef(*getOptions().WarningsAsErrors)
246+
: StringRef(""));
247+
static const std::vector<std::string> EmptyFileExtensions;
248+
if (!parseFileExtensions(getOptions().HeaderFileExtensions
249+
? *getOptions().HeaderFileExtensions
250+
: EmptyFileExtensions,
246251
HeaderFileExtensions))
247252
this->configurationDiag("Invalid header file extensions");
248-
if (!parseFileExtensions(*getOptions().ImplementationFileExtensions,
253+
if (!parseFileExtensions(getOptions().ImplementationFileExtensions
254+
? *getOptions().ImplementationFileExtensions
255+
: EmptyFileExtensions,
249256
ImplementationFileExtensions))
250257
this->configurationDiag("Invalid implementation file extensions");
251258
}
@@ -569,7 +576,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
569576
return;
570577
}
571578

572-
if (!*Context.getOptions().SystemHeaders &&
579+
if (!Context.getOptions().SystemHeaders.value_or(false) &&
573580
(Sources.isInSystemHeader(Location) || Sources.isInSystemMacro(Location)))
574581
return;
575582

@@ -600,15 +607,19 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
600607

601608
llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
602609
if (!HeaderFilter)
603-
HeaderFilter =
604-
std::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
610+
HeaderFilter = std::make_unique<llvm::Regex>(
611+
Context.getOptions().HeaderFilterRegex
612+
? StringRef(*Context.getOptions().HeaderFilterRegex)
613+
: StringRef(""));
605614
return HeaderFilter.get();
606615
}
607616

608617
llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
609618
if (!ExcludeHeaderFilter)
610619
ExcludeHeaderFilter = std::make_unique<llvm::Regex>(
611-
*Context.getOptions().ExcludeHeaderFilterRegex);
620+
Context.getOptions().ExcludeHeaderFilterRegex
621+
? StringRef(*Context.getOptions().ExcludeHeaderFilterRegex)
622+
: StringRef(""));
612623
return ExcludeHeaderFilter.get();
613624
}
614625

clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS,
5757

5858
void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG,
5959
const StorageParams &Storage) {
60+
assert(this->Storage && "We should have a filename.");
6061
llvm::SmallString<256> OutputDirectory(Storage.StoreFilename);
6162
llvm::sys::path::remove_filename(OutputDirectory);
6263
if (const std::error_code EC =

clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void RedundantBranchConditionCheck::check(
132132

133133
// If the other side has side effects then keep it.
134134
if (OtherSide && OtherSide->HasSideEffects(*Result.Context)) {
135-
auto NextToken = Lexer::findNextToken(
135+
const auto NextToken = Lexer::findNextToken(
136136
OtherSide->getEndLoc(), *Result.SourceManager, getLangOpts());
137137
if (NextToken) {
138138
const SourceLocation BeforeOtherSide =
@@ -167,7 +167,7 @@ void RedundantBranchConditionCheck::check(
167167
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
168168
CondOp->getLHS()->getBeginLoc(), BeforeRHS));
169169
} else {
170-
auto NextToken = Lexer::findNextToken(
170+
const auto NextToken = Lexer::findNextToken(
171171
CondOp->getLHS()->getEndLoc(), *Result.SourceManager, getLangOpts());
172172
if (NextToken) {
173173
const SourceLocation AfterLHS = NextToken->getLocation();

0 commit comments

Comments
 (0)