[PATCH] D91614: [clang-tidy] Fix a nullptr-access crash in unused-raii-check.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 17 04:33:39 PST 2020
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
hokein requested review of this revision.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91614
Files:
clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -79,12 +79,11 @@
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91614.305738.patch
Type: text/x-patch
Size: 929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201117/5b4a268a/attachment-0001.bin>
More information about the cfe-commits
mailing list