[llvm-branch-commits] [clang-tools-extra] 3d2c681 - [clangd] Avoid type hierarchy crash on incomplete type
Nathan Ridge via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 25 00:49:43 PST 2020
Author: Nathan Ridge
Date: 2020-11-25T03:45:00-05:00
New Revision: 3d2c681f2835261599654c1b82dacdae05c9b4c4
URL: https://github.com/llvm/llvm-project/commit/3d2c681f2835261599654c1b82dacdae05c9b4c4
DIFF: https://github.com/llvm/llvm-project/commit/3d2c681f2835261599654c1b82dacdae05c9b4c4.diff
LOG: [clangd] Avoid type hierarchy crash on incomplete type
Fixes https://github.com/clangd/clangd/issues/597
Differential Revision: https://reviews.llvm.org/D92077
Added:
Modified:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 31e963cb853f..8a85507ff14c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1553,6 +1553,10 @@ std::vector<const CXXRecordDecl *> typeParents(const CXXRecordDecl *CXXRD) {
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;
diff --git a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
index 64831724d1be..08f936ce8b55 100644
--- a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -30,6 +30,7 @@ namespace {
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::Field;
+using ::testing::IsEmpty;
using ::testing::Matcher;
using ::testing::UnorderedElementsAre;
@@ -318,6 +319,18 @@ struct Child3 : T {};
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.
More information about the llvm-branch-commits
mailing list