kadircet updated this revision to Diff 520648. kadircet marked 3 inline comments as done. kadircet added a comment.
Merge with existing tests Perform check earlier Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150187/new/ https://reviews.llvm.org/D150187 Files: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp @@ -3,3 +3,14 @@ // This used to cause a null pointer dereference. auto [left] = right; // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right' + +namespace crash_on_nonidentifiers { +struct Foo { + operator bool(); +}; +void foo() { + // Make sure we don't crash on non-identifier names (e.g. conversion + // operators). + if (Foo()) {} +} +} Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -448,14 +448,18 @@ void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range, const SourceManager *SourceMgr) { + // Don't keep track for non-identifier names. + auto *II = Decl->getIdentifier(); + if (!II) + return; if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Decl = Overridden; } Decl = cast<NamedDecl>(Decl->getCanonicalDecl()); - return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), - Decl->getName()), - Range, SourceMgr); + return addUsage( + RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()), + Range, SourceMgr); } void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp @@ -3,3 +3,14 @@ // This used to cause a null pointer dereference. auto [left] = right; // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right' + +namespace crash_on_nonidentifiers { +struct Foo { + operator bool(); +}; +void foo() { + // Make sure we don't crash on non-identifier names (e.g. conversion + // operators). + if (Foo()) {} +} +} Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -448,14 +448,18 @@ void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range, const SourceManager *SourceMgr) { + // Don't keep track for non-identifier names. + auto *II = Decl->getIdentifier(); + if (!II) + return; if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) { if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) Decl = Overridden; } Decl = cast<NamedDecl>(Decl->getCanonicalDecl()); - return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), - Decl->getName()), - Range, SourceMgr); + return addUsage( + RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()), + Range, SourceMgr); } void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits