[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
Sun Feb 2 06:07:53 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd591bdce6d62: [clang-tidy] Fixed crash 44745 in readability-else-after-return (authored by njames93).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73841/new/

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;
+}
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.241921.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200202/f05b555c/attachment.bin>


More information about the cfe-commits mailing list