[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 00:30:08 PDT 2020
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
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
@@ -1243,7 +1243,31 @@
"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(
+ namespace foo {
+ struct $0^ForwardDecl;
+ template<typename $1^T>
+ void $2^crash(const $3^ForwardDecl&, $4^T &);
+ template<typename $5^T>
+ void $6^test($7^T $8^t) {
+ $9^crash({.x = 1}, $10^t);
+ }
+ }
+ )cpp",
+ "0: targets = {foo::ForwardDecl}, decl\n"
+ "1: targets = {T}, decl\n"
+ "2: targets = {foo::crash}, decl\n"
+ "3: targets = {foo::ForwardDecl}\n"
+ "4: targets = {T}\n"
+ "5: targets = {T}, decl\n"
+ "6: targets = {foo::test}, decl\n"
+ "7: targets = {T}\n"
+ "8: targets = {t}, decl\n"
+ "9: targets = {foo::crash}\n"
+ "10: 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
@@ -699,6 +699,8 @@
for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
if (!D.isFieldDesignator())
continue;
+ if (!D.getField())
+ continue;
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
D.getFieldLoc(),
/*IsDecl=*/false,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78181.257610.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200415/43a941c4/attachment.bin>
More information about the cfe-commits
mailing list