forked from OSchip/llvm-project
[clangd] Fix a crash for accessing a null field decl returned by findExplicitReferences.
Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78181
This commit is contained in:
parent
e98c2733d2
commit
6a78c55e3a
|
@ -714,10 +714,12 @@ llvm::SmallVector<ReferenceLoc, 2> refInExpr(const Expr *E) {
|
|||
for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
|
||||
if (!D.isFieldDesignator())
|
||||
continue;
|
||||
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
|
||||
D.getFieldLoc(),
|
||||
/*IsDecl=*/false,
|
||||
{D.getField()}});
|
||||
|
||||
llvm::SmallVector<const NamedDecl *, 1> Targets;
|
||||
if (D.getField())
|
||||
Targets.push_back(D.getField());
|
||||
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), D.getFieldLoc(),
|
||||
/*IsDecl=*/false, std::move(Targets)});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1273,7 +1273,20 @@ TEST_F(FindExplicitReferencesTest, All) {
|
|||
"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(
|
||||
template<typename T>
|
||||
void crash(T);
|
||||
template<typename T>
|
||||
void foo() {
|
||||
$0^crash({.$1^x = $2^T()});
|
||||
}
|
||||
)cpp",
|
||||
"0: targets = {crash}\n"
|
||||
"1: targets = {}\n"
|
||||
"2: targets = {T}\n"
|
||||
},
|
||||
};
|
||||
|
||||
for (const auto &C : Cases) {
|
||||
llvm::StringRef ExpectedCode = C.first;
|
||||
|
|
Loading…
Reference in New Issue