[PATCH] D153617: [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename

2023-07-14 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5649b24c48ab: [clangd] Fix an assertion failure in 
NamedDecl::getName during the prepareRename (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153617/new/

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
@@ -1129,6 +1129,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
@@ -332,7 +332,8 @@
   return nullptr;
 for (const auto  : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND !=  && ND->getName() == Name)
+if (ND !=  && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1129,6 +1129,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
@@ -332,7 +332,8 @@
   return nullptr;
 for (const auto  : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND !=  && ND->getName() == Name)
+if (ND !=  && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153617: [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
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  : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND !=  && ND->getName() == Name)
+if (ND !=  && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };


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  : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND !=  && ND->getName() == Name)
+if (ND !=  && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits