[PATCH] D102001: [Index] Ignore nullptr decls for indexing

Alex Hoppen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 6 09:52:42 PDT 2021


ahoppen created this revision.
Herald added a subscriber: arphaman.
ahoppen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102001

Files:
  clang/lib/Index/IndexDecl.cpp


Index: clang/lib/Index/IndexDecl.cpp
===================================================================
--- clang/lib/Index/IndexDecl.cpp
+++ clang/lib/Index/IndexDecl.cpp
@@ -759,7 +759,7 @@
 }
 
 bool IndexingContext::indexTopLevelDecl(const Decl *D) {
-  if (D->getLocation().isInvalid())
+  if (!D || D->getLocation().isInvalid())
     return true;
 
   if (isa<ObjCMethodDecl>(D))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102001.343440.patch
Type: text/x-patch
Size: 387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210506/b6ea8874/attachment-0001.bin>


More information about the cfe-commits mailing list