[PATCH] D153617: [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 23 02:00:04 PDT 2023
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
getName method required to be called on a simple-identifier NamedDecl,
otherwise it will trigger an assertion.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153617
Files:
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1106,6 +1106,15 @@
using ns::^foo;
)cpp",
"there are multiple symbols at the given location", !HeaderFile},
+
+ {R"cpp(
+ void test() {
+ // no crash
+ using namespace std;
+ int [[V^ar]];
+ }
+ )cpp",
+ nullptr, !HeaderFile},
};
for (const auto& Case : Cases) {
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -318,7 +318,8 @@
return nullptr;
for (const auto &Child : DS->getDeclGroup())
if (const auto *ND = dyn_cast<NamedDecl>(Child))
- if (ND != &RenamedDecl && ND->getName() == Name)
+ if (ND != &RenamedDecl && ND->getDeclName().isIdentifier() &&
+ ND->getName() == Name)
return ND;
return nullptr;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153617.533901.patch
Type: text/x-patch
Size: 1174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230623/32d52899/attachment-0001.bin>
More information about the cfe-commits
mailing list