[PATCH] D158851: [clangd] Avoid null result in FindRecordTypeAt()
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 25 08:16:23 PDT 2023
nridge created this revision.
nridge added reviewers: kadircet, hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158851
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
@@ -78,6 +78,19 @@
}
}
+TEST(FindRecordTypeAt, Nonexistent) {
+ Annotations Source(R"cpp(
+ int *wa^ldo;
+ )cpp");
+ TestTU TU = TestTU::withCode(Source.code());
+ auto AST = TU.build();
+
+ for (Position Pt : Source.points()) {
+ auto Records = findRecordTypeAt(AST, Pt);
+ ASSERT_THAT(Records, SizeIs(0));
+ }
+}
+
TEST(FindRecordTypeAt, Method) {
Annotations Source(R"cpp(
struct Child2 {
@@ -119,7 +132,7 @@
for (Position Pt : Source.points()) {
// A field does not unambiguously specify a record type
- // (possible associated reocrd types could be the field's type,
+ // (possible associated record types could be the field's type,
// or the type of the record that the field is a member of).
EXPECT_THAT(findRecordTypeAt(AST, Pt), SizeIs(0));
}
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1854,7 +1854,8 @@
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
// If this is a variable, use the type of the variable.
- Records.push_back(VD->getType().getTypePtr()->getAsCXXRecordDecl());
+ if (const auto *RD = VD->getType().getTypePtr()->getAsCXXRecordDecl())
+ Records.push_back(RD);
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158851.553485.patch
Type: text/x-patch
Size: 1618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230825/9e06a24e/attachment.bin>
More information about the cfe-commits
mailing list