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;
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;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits