[clang-tools-extra] 66ace4d - [clang-tidy] Fix a nullptr-access crash in unused-raii-check.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 00:44:40 PST 2020
Author: Haojian Wu
Date: 2020-11-23T09:44:19+01:00
New Revision: 66ace4dc0275c8d7740bc5ff57c20e85e6660371
URL: https://github.com/llvm/llvm-project/commit/66ace4dc0275c8d7740bc5ff57c20e85e6660371
DIFF: https://github.com/llvm/llvm-project/commit/66ace4dc0275c8d7740bc5ff57c20e85e6660371.diff
LOG: [clang-tidy] Fix a nullptr-access crash in unused-raii-check.
I saw this crash in our internal production, but unfortunately didn't get
reproduced testcase, we likely hit this crash when the AST is ill-formed
(e.g. broken code).
Reviewed By: gribozavr2
Differential Revision: https://reviews.llvm.org/D91614
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
index 70ce413d20ff..5e4a0ba6d569 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -79,12 +79,11 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult &Result) {
// written type.
auto Matches =
match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
- const auto *TL = selectFirst<TypeLoc>("t", Matches);
- assert(TL);
- D << FixItHint::CreateInsertion(
- Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
- getLangOpts()),
- Replacement);
+ if (const auto *TL = selectFirst<TypeLoc>("t", Matches))
+ D << FixItHint::CreateInsertion(
+ Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
+ getLangOpts()),
+ Replacement);
}
} // namespace bugprone
More information about the cfe-commits
mailing list