Skip to content

Commit

Permalink
fix(cxx_indexer): handle null init expr (#4622)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahms committed Aug 3, 2020
1 parent 88c36a0 commit bcdc8e9
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Expand Up @@ -1923,21 +1923,24 @@ bool IndexerASTVisitor::VisitInitListExpr(const clang::InitListExpr* ILE) {
LogErrorWithASTDump("Fewer initializers than decls:\n", ILE);
break;
}
const clang::Expr* Init = *II++;
clang::SourceRange InitRange = NormalizeRange(Init->getSourceRange());
if (!(InitRange.isValid() && ListRange.fullyContains(InitRange))) {
// When visiting the semantic form initializers which aren't explicitly
// specified either have an invalid location (for uninitialized fields) or
// share a location with the end of the ILE (for default initialized
// fields). Skip these by checking that their location is wholly contained
// by the syntactic initializers, rather than the enclosing ILE itself.
continue;
}
if (auto RCC = RangeInCurrentContext(BuildNodeIdForImplicitStmt(Init),
InitRange)) {
Observer.recordInitLocation(*RCC, BuildNodeIdForRefToDecl(Decl),
GraphObserver::Claimability::Unclaimable,
this->IsImplicit(*RCC));
// On rare occasions, the init Expr we get from clang is null.
if (const clang::Expr* Init = *II++) {
clang::SourceRange InitRange = NormalizeRange(Init->getSourceRange());
if (!(InitRange.isValid() && ListRange.fullyContains(InitRange))) {
// When visiting the semantic form initializers which aren't explicitly
// specified either have an invalid location (for uninitialized fields)
// or share a location with the end of the ILE (for default initialized
// fields). Skip these by checking that their location is wholly
// contained by the syntactic initializers, rather than the enclosing
// ILE itself.
continue;
}
if (auto RCC = RangeInCurrentContext(BuildNodeIdForImplicitStmt(Init),
InitRange)) {
Observer.recordInitLocation(*RCC, BuildNodeIdForRefToDecl(Decl),
GraphObserver::Claimability::Unclaimable,
this->IsImplicit(*RCC));
}
}
}
return true;
Expand Down

0 comments on commit bcdc8e9

Please sign in to comment.