[PATCH] D92077: [clangd] Avoid type hierarchy crash on incomplete type

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 00:45:30 PST 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d2c681f2835: [clangd] Avoid type hierarchy crash on incomplete type (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92077

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp


Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -30,6 +30,7 @@
 using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::UnorderedElementsAre;
 
@@ -318,6 +319,18 @@
   EXPECT_THAT(typeParents(Child3), ElementsAre());
 }
 
+TEST(TypeParents, IncompleteClass) {
+  Annotations Source(R"cpp(
+    class Incomplete;
+  )cpp");
+  TestTU TU = TestTU::withCode(Source.code());
+  auto AST = TU.build();
+
+  const CXXRecordDecl *Incomplete =
+      dyn_cast<CXXRecordDecl>(&findDecl(AST, "Incomplete"));
+  EXPECT_THAT(typeParents(Incomplete), IsEmpty());
+}
+
 // Parts of getTypeHierarchy() are tested in more detail by the
 // FindRecordTypeAt.* and TypeParents.* tests above. This test exercises the
 // entire operation.
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1553,6 +1553,10 @@
       CXXRD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
   }
 
+  // Can't query bases without a definition.
+  if (!CXXRD->hasDefinition())
+    return Result;
+
   for (auto Base : CXXRD->bases()) {
     const CXXRecordDecl *ParentDecl = nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92077.307533.patch
Type: text/x-patch
Size: 1501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201125/77744e29/attachment.bin>


More information about the cfe-commits mailing list