Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44745 | readability-else-after-return crashes ]]
Reviewers: aaron.ballman, alexfh, hokein, JonasToth, gribozavr2
Reviewed By: alexfh
Subscribers: merge_guards_bot, xazax.hun, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D73841
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;
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;
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;
+}