[llvm-branch-commits] [clang-tools-extra] 445289a - [clangd] Fix an assertion violation in rename.

Haojian Wu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 4 03:27:50 PST 2020


Author: Haojian Wu
Date: 2020-12-04T12:23:26+01:00
New Revision: 445289aa63e1b82b9eea6497fb2d0443813a9d4e

URL: https://github.com/llvm/llvm-project/commit/445289aa63e1b82b9eea6497fb2d0443813a9d4e
DIFF: https://github.com/llvm/llvm-project/commit/445289aa63e1b82b9eea6497fb2d0443813a9d4e.diff

LOG: [clangd] Fix an assertion violation in rename.

NamedDecl::getName() asserts the name must be an identifier.

Differential Revision: https://reviews.llvm.org/D92642

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 0af8a98427c7..8ed5811c88b2 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -637,7 +637,10 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
   if (DeclsUnderCursor.size() > 1)
     return makeError(ReasonToReject::AmbiguousSymbol);
   const auto &RenameDecl = **DeclsUnderCursor.begin();
-  if (RenameDecl.getName() == RInputs.NewName)
+  const auto *ID = RenameDecl.getIdentifier();
+  if (!ID)
+    return makeError(ReasonToReject::UnsupportedSymbol);
+  if (ID->getName() == RInputs.NewName)
     return makeError(ReasonToReject::SameName);
   auto Invalid = checkName(RenameDecl, RInputs.NewName);
   if (Invalid)

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 306909892509..0aa87c61baeb 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -946,6 +946,13 @@ TEST(RenameTest, Renameable) {
        )cpp",
        "not a supported kind", !HeaderFile, Index},
 
+      {R"cpp(// disallow rename on non-normal identifiers.
+         @interface Foo {}
+         -(int) fo^o:(int)x; // Token is an identifier, but declaration name isn't a simple identifier.
+         @end
+       )cpp",
+       "not a supported kind", HeaderFile, Index},
+
       {R"cpp(
          void foo(int);
          void foo(char);


        


More information about the llvm-branch-commits mailing list