[PATCH] D79582: [clangd] Fix crash in AddUsing tweak due to non-identifier DeclName

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 8 05:19:57 PDT 2020


adamcz updated this revision to Diff 262857.
adamcz marked an inline comment as done.
adamcz added a comment.

Addressed review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79582

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2444,6 +2444,7 @@
 public:
   struct st {};
   static void mm() {}
+  cc operator|(const cc& x) const { return x; }
 };
 }
 })cpp";
@@ -2463,6 +2464,9 @@
   // test that we don't crash.
   EXPECT_UNAVAILABLE(Header +
                      "template<typename TT> using foo = one::tt<T^T>;");
+  // Test that we don't crash or misbehave on unnamed DeclRefExpr.
+  EXPECT_UNAVAILABLE(Header +
+                     "void fun() { one::two::cc() ^| one::two::cc(); }");
 
   // Check that we do not trigger in header files.
   FileName = "test.h";
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -210,8 +210,10 @@
     return false;
 
   if (auto *D = Node->ASTNode.get<DeclRefExpr>()) {
-    QualifierToRemove = D->getQualifierLoc();
-    Name = D->getDecl()->getName();
+    if (auto *II = D->getDecl()->getIdentifier()) {
+      QualifierToRemove = D->getQualifierLoc();
+      Name = II->getName();
+    }
   } else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
     if (auto E = T->getAs<ElaboratedTypeLoc>()) {
       if (auto *BaseTypeIdentifier =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79582.262857.patch
Type: text/x-patch
Size: 1487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200508/8c47114e/attachment-0001.bin>


More information about the cfe-commits mailing list