Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp @@ -13,6 +13,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Token.h" +#include "llvm/Support/Path.h" namespace clang { namespace find_all_symbols { @@ -30,8 +31,11 @@ // If Collector is not nullptr, check pragma remapping header. FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath; + SmallString<256> CleanedFilePath = FilePath; + llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/true); + SymbolInfo Symbol(MacroNameTok.getIdentifierInfo()->getName(), - SymbolInfo::SymbolKind::Macro, FilePath.str(), + SymbolInfo::SymbolKind::Macro, CleanedFilePath, SM->getSpellingLineNumber(Loc), {}); Reporter->reportSymbol(SM->getFileEntryForID(SM->getMainFileID())->getName(), Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp @@ -99,7 +99,10 @@ // If Collector is not nullptr, check pragma remapping header. FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath; - return SymbolInfo(ND->getNameAsString(), Type, FilePath.str(), + SmallString<256> CleanedFilePath = FilePath; + llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/true); + + return SymbolInfo(ND->getNameAsString(), Type, CleanedFilePath, SM.getExpansionLineNumber(Loc), GetContexts(ND)); } Index: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp +++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp @@ -90,13 +90,28 @@ InMemoryFileSystem->addFile(HeaderName, 0, llvm::MemoryBuffer::getMemBuffer(Code)); + // Test path cleaning for both decls and macros. + const std::string DirtyHeader = "./internal/../internal/./a/b.h"; + const std::string CleanHeader = "internal/a/b.h"; + const std::string DirtyHeaderContent = + "#define INTERNAL 1\nclass ExtraInternal {};"; + InMemoryFileSystem->addFile( + DirtyHeader, 0, llvm::MemoryBuffer::getMemBuffer(DirtyHeaderContent)); + SymbolInfo DirtyMacro("INTERNAL", SymbolInfo::SymbolKind::Macro, + CleanHeader, 1, {}); + SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class, + CleanHeader, 2, {}); + std::string Content = "#include\"" + std::string(HeaderName) + "\"\n" - "#include \"internal/internal.h\""; + "#include \"internal/internal.h\"\n" + "#include \"" + DirtyHeader + "\""; InMemoryFileSystem->addFile(FileName, 0, llvm::MemoryBuffer::getMemBuffer(Content)); Invocation.run(); EXPECT_TRUE(hasSymbol(InternalSymbol)); + EXPECT_TRUE(hasSymbol(DirtySymbol)); + EXPECT_TRUE(hasSymbol(DirtyMacro)); return true; }