[Index] Ignore nullptr decls for indexing
authorAlex Hoppen <ahoppen@apple.com>
Thu, 6 May 2021 20:11:26 +0000 (13:11 -0700)
committerArgyrios Kyrtzidis <kyrtzidis@apple.com>
Thu, 6 May 2021 20:12:26 +0000 (13:12 -0700)
We can end up with a call to `indexTopLevelDecl(D)` with `D == nullptr` in non-assert builds e.g. when indexing a module in `indexModule` and
- `ASTReader::GetDecl` returns `nullptr` if `Index >= DeclsLoaded.size()`, thus returning `nullptr`
=> `ModuleDeclIterator::operator*` returns `nullptr`
=> we call `IndexCtx.indexTopLevelDecl` with `nullptr`

Be resilient and just ignore the `nullptr` decls during indexing.

Reviewed By: akyrtzi

Differential Revision: https://reviews.llvm.org/D102001

clang/lib/Index/IndexDecl.cpp

index 2ba323e..00adb36 100644 (file)
@@ -759,7 +759,7 @@ bool IndexingContext::indexDeclContext(const DeclContext *DC) {
 }
 
 bool IndexingContext::indexTopLevelDecl(const Decl *D) {
-  if (D->getLocation().isInvalid())
+  if (!D || D->getLocation().isInvalid())
     return true;
 
   if (isa<ObjCMethodDecl>(D))