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;


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;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to