[PATCH] D73841: [clang-tidy] Fixed crash 44745 in readability-else-after-return
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 1 13:20:14 PST 2020
njames93 created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73841
Files:
clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-else-after-return.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-else-after-return.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-else-after-return.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-else-after-return.cpp
@@ -213,3 +213,16 @@
return b;
}
}
+
+void test_B44745() {
+ // This is the actual minimum test case for the crash in bug 44745. We aren't
+ // too worried about the warning or fix here, more we don't want a crash.
+ // CHECK-MESSAGES: :[[@LINE+3]]:5: warning: do not use 'else' after 'return' [readability-else-after-return]
+ if (auto X = false) {
+ return;
+ } else {
+ for (;;) {
+ }
+ }
+ return;
+}
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -27,6 +27,8 @@
static const char WarnOnUnfixableStr[] = "WarnOnUnfixable";
const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
+ if (!Node)
+ return nullptr;
if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Node)) {
if (DeclRef->getDecl()->getID() == DeclIdentifier) {
return DeclRef;
@@ -44,6 +46,8 @@
const DeclRefExpr *
findUsageRange(const Stmt *Node,
const llvm::iterator_range<int64_t *> &DeclIdentifiers) {
+ if (!Node)
+ return nullptr;
if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Node)) {
if (llvm::is_contained(DeclIdentifiers, DeclRef->getDecl()->getID())) {
return DeclRef;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73841.241901.patch
Type: text/x-patch
Size: 1726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200201/a4c414ab/attachment.bin>
More information about the cfe-commits
mailing list