[clang-tools-extra] b36a2e7 - [tidy][IdentifierNaming] Fix crashes on non-identifiers
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue May 9 03:51:04 PDT 2023
Author: Kadir Cetinkaya
Date: 2023-05-09T12:50:57+02:00
New Revision: b36a2e7828befcf948f461b72c78a8d2386db2e7
URL: https://github.com/llvm/llvm-project/commit/b36a2e7828befcf948f461b72c78a8d2386db2e7
DIFF: https://github.com/llvm/llvm-project/commit/b36a2e7828befcf948f461b72c78a8d2386db2e7.diff
LOG: [tidy][IdentifierNaming] Fix crashes on non-identifiers
Differential Revision: https://reviews.llvm.org/D150187
Added:
Modified:
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 5347dadf18ac5..ee400d88a3a74 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@ void RenamerClangTidyCheck::addUsage(
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,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
index 9f892ebceccf2..25f2c71a316d7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ b/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()) {}
+}
+}
More information about the cfe-commits
mailing list