r316764 - [CrossTU] Fix handling of Cross Translation Unit directory path
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 27 05:53:37 PDT 2017
Author: xazax
Date: Fri Oct 27 05:53:37 2017
New Revision: 316764
URL: http://llvm.org/viewvc/llvm-project?rev=316764&view=rev
Log:
[CrossTU] Fix handling of Cross Translation Unit directory path
Differential Revision: https://reviews.llvm.org/D38842
Modified:
cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
Modified: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp?rev=316764&r1=316763&r2=316764&view=diff
==============================================================================
--- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp (original)
+++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp Fri Oct 27 05:53:37 2017
@@ -93,10 +93,7 @@ parseCrossTUIndex(StringRef IndexPath, S
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<IndexError>(
Modified: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp?rev=316764&r1=316763&r2=316764&view=diff
==============================================================================
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp (original)
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp Fri Oct 27 05:53:37 2017
@@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, CanLoadFuncti
TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
llvm::StringMap<std::string> 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, IndexFormatCa
EXPECT_TRUE(Index.count(E.getKey()));
}
+TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
+ llvm::StringMap<std::string> 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<llvm::StringMap<std::string>> IndexOrErr =
+ parseCrossTUIndex(IndexFileName, "/ctudir");
+ EXPECT_TRUE((bool)IndexOrErr);
+ llvm::StringMap<std::string> ParsedIndex = IndexOrErr.get();
+ EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
+}
+
} // end namespace cross_tu
} // end namespace clang
More information about the cfe-commits
mailing list