From 724beacadcc97c70e214d6e822f106b43ac1235c Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Fri, 27 Oct 2017 12:53:37 +0000 Subject: [PATCH] [CrossTU] Fix handling of Cross Translation Unit directory path Differential Revision: https://reviews.llvm.org/D38842 llvm-svn: 316764 --- clang/lib/CrossTU/CrossTranslationUnit.cpp | 5 +--- .../CrossTU/CrossTranslationUnitTest.cpp | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index a503578da051..e20ea7702237 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -93,10 +93,7 @@ parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir) { index_error_code::multiple_definitions, IndexPath.str(), LineNo); StringRef FileName = LineRef.substr(Pos + 1); SmallString<256> FilePath = CrossTUDir; - if (llvm::sys::path::is_absolute(FileName)) - FilePath = FileName; - else - llvm::sys::path::append(FilePath, FileName); + llvm::sys::path::append(FilePath, FileName); Result[FunctionLookupName] = FilePath.str().str(); } else return llvm::make_error( diff --git a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp index 795a4351b501..5fbf56ed43b8 100644 --- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, CanLoadFunctionDefinition) { TEST(CrossTranslationUnit, IndexFormatCanBeParsed) { llvm::StringMap Index; - Index["a"] = "b"; - Index["c"] = "d"; - Index["e"] = "f"; + Index["a"] = "/b/f1"; + Index["c"] = "/d/f2"; + Index["e"] = "/f/f3"; std::string IndexText = createCrossTUIndexString(Index); int IndexFD; @@ -134,5 +134,25 @@ TEST(CrossTranslationUnit, IndexFormatCanBeParsed) { EXPECT_TRUE(Index.count(E.getKey())); } +TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) { + llvm::StringMap Index; + Index["a"] = "/b/c/d"; + std::string IndexText = createCrossTUIndexString(Index); + + int IndexFD; + llvm::SmallString<256> IndexFileName; + ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD, + IndexFileName)); + llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD); + IndexFile.os() << IndexText; + IndexFile.os().flush(); + EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName)); + llvm::Expected> IndexOrErr = + parseCrossTUIndex(IndexFileName, "/ctudir"); + EXPECT_TRUE((bool)IndexOrErr); + llvm::StringMap ParsedIndex = IndexOrErr.get(); + EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d"); +} + } // end namespace cross_tu } // end namespace clang