[PATCH] D78181: [clangd] Fix a crash for accessing a null field decl returned by findExplicitReferences.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 15 08:12:06 PDT 2020


hokein updated this revision to Diff 257718.
hokein added a comment.

emit empty decl and simplify the testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78181

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1273,7 +1273,20 @@
         "5: targets = {Bar}\n"
         "6: targets = {bar}, decl\n"
         "7: targets = {foo()::Bar::Foo}\n"
-        "8: targets = {foo()::Baz::Field}\n"}};
+        "8: targets = {foo()::Baz::Field}\n"},
+      {R"cpp(
+           template<typename T>
+           void crash(T);
+           template<typename T>
+           void foo() {
+             $0^crash({.$1^x = $2^T()});
+           }
+        )cpp",
+        "0: targets = {crash}\n"
+        "1: targets = {}\n"
+        "2: targets = {T}\n"
+      },
+    };
 
   for (const auto &C : Cases) {
     llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -714,10 +714,12 @@
       for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
         if (!D.isFieldDesignator())
           continue;
-        Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
-                                    D.getFieldLoc(),
-                                    /*IsDecl=*/false,
-                                    {D.getField()}});
+
+        llvm::SmallVector<const NamedDecl *, 1> Targets;
+        if (D.getField())
+          Targets.push_back(D.getField());
+        Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), D.getFieldLoc(),
+                                    /*IsDecl=*/false, std::move(Targets)});
       }
     }
   };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78181.257718.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200415/634121f3/attachment-0001.bin>


More information about the cfe-commits mailing list