From bcdc8e9df40a540ca4e04c75f95f83b0950c264b Mon Sep 17 00:00:00 2001 From: Shahms King Date: Mon, 3 Aug 2020 13:16:09 -0700 Subject: [PATCH] fix(cxx_indexer): handle null init expr (#4622) --- kythe/cxx/indexer/cxx/IndexerASTHooks.cc | 33 +++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/kythe/cxx/indexer/cxx/IndexerASTHooks.cc b/kythe/cxx/indexer/cxx/IndexerASTHooks.cc index 9771fccc96..904758c08f 100644 --- a/kythe/cxx/indexer/cxx/IndexerASTHooks.cc +++ b/kythe/cxx/indexer/cxx/IndexerASTHooks.cc @@ -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;