Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -211,7 +211,10 @@ const SymbolCollector::Options &Opts, const clang::LangOptions &LangOpts, std::string &FileURIStorage) { - auto U = toURI(SM, SM.getFilename(TokLoc), Opts); + llvm::StringRef FileName = SM.getFilename(TokLoc); + if (FileName.empty()) + return None; + auto U = toURI(SM, FileName, Opts); if (!U) return None; FileURIStorage = std::move(*U); Index: unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- unittests/clangd/SymbolCollectorTests.cpp +++ unittests/clangd/SymbolCollectorTests.cpp @@ -1028,6 +1028,15 @@ AllOf(QName("Public"), Not(ImplementationDetail())))); } +TEST_F(SymbolCollectorTest, RenameSymbolWithMacro) { + const std::string Header = R"( + void foo() {} + )"; + runSymbolCollector(Header, /*Main=*/"", {"-Dfoo=bar"}); + EXPECT_THAT(Symbols, UnorderedElementsAre(QName("bar"))); +} + + } // namespace } // namespace clangd } // namespace clang