[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 9 03:50:25 PDT 2023
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150187.520648.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230509/36614ac9/attachment.bin>
More information about the cfe-commits
mailing list