diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 1ad75e14cba4..568dff9594a4 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -371,7 +371,6 @@ bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name, Roles & static_cast(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();