[clang-tools-extra] 5649b24 - [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 14 00:17:54 PDT 2023
Author: Haojian Wu
Date: 2023-07-14T09:17:46+02:00
New Revision: 5649b24c48ab3b48c1cb89155626a7f128c3f598
URL: https://github.com/llvm/llvm-project/commit/5649b24c48ab3b48c1cb89155626a7f128c3f598
DIFF: https://github.com/llvm/llvm-project/commit/5649b24c48ab3b48c1cb89155626a7f128c3f598.diff
LOG: [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename
getName method required to be called on a simple-identifier NamedDecl,
otherwise it will trigger an assertion.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D153617
Added:
Modified:
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 97ea5e1836579c..11f9e4627af760 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -332,7 +332,8 @@ const NamedDecl *lookupSiblingWithinEnclosingScope(ASTContext &Ctx,
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;
};
diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 2414ff6b64c3f2..9cbf59684fbc10 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1129,6 +1129,15 @@ TEST(RenameTest, Renameable) {
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) {
More information about the cfe-commits
mailing list