[clang][index] Fix a crash for accessing a null field decl.

getField() may return a nullptr, we already did that in
BodyIndexer::VisitDesignatedInitExpr, but missed one place.
This commit is contained in:
Haojian Wu 2020-05-20 23:15:08 +02:00
parent 1c3d9c2f36
commit c2c36c4f4b
2 changed files with 9 additions and 1 deletions

View File

@ -414,7 +414,7 @@ public:
auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool {
for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
if (D.isFieldDesignator())
if (D.isFieldDesignator() && D.getField())
return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
Parent, ParentDC, SymbolRoleSet(),
{}, E);

View File

@ -0,0 +1,8 @@
struct Bar {};
struct Foo {
void method(Bar bar) {}
};
void NoCrash(Foo t) {
t.method({.abc = 50}); // CHECK: field designator 'abc' does not refer to any field in type 'Bar'
}
// RUN: c-index-test -index-file %s -Xclang -frecovery-ast 2>&1 | FileCheck %s