[clangd] Make sure macro information exists before increasing usage count.
authorEric Liu <ioeric@google.com>
Mon, 9 Jul 2018 18:54:51 +0000 (18:54 +0000)
committerEric Liu <ioeric@google.com>
Mon, 9 Jul 2018 18:54:51 +0000 (18:54 +0000)
llvm-svn: 336581

clang-tools-extra/clangd/index/SymbolCollector.cpp

index 1ad75e1..568dff9 100644 (file)
@@ -371,7 +371,6 @@ bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name,
         Roles & static_cast<unsigned>(index::SymbolRole::Definition)))
     return true;
 
-
   llvm::SmallString<128> USR;
   if (index::generateUSRForMacro(Name->getName(), MI->getDefinitionLoc(), SM,
                                  USR))
@@ -433,11 +432,10 @@ void SymbolCollector::finish() {
     assert(PP);
     for (const IdentifierInfo *II : ReferencedMacros) {
       llvm::SmallString<128> USR;
-      if (!index::generateUSRForMacro(
-              II->getName(),
-              PP->getMacroDefinition(II).getMacroInfo()->getDefinitionLoc(),
-              PP->getSourceManager(), USR))
-        IncRef(SymbolID(USR));
+      if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo())
+        if (!index::generateUSRForMacro(II->getName(), MI->getDefinitionLoc(),
+                                        PP->getSourceManager(), USR))
+          IncRef(SymbolID(USR));
     }
   }
   ReferencedDecls.clear();