Skip to content

Commit

Permalink
[CrossTU] Fix handling of Cross Translation Unit directory path
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D38842

llvm-svn: 316764
  • Loading branch information
Xazax-hun committed Oct 27, 2017
1 parent be684ee commit 724beac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 1 addition & 4 deletions clang/lib/CrossTU/CrossTranslationUnit.cpp
Expand Up @@ -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<IndexError>(
Expand Down
26 changes: 23 additions & 3 deletions clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
Expand Up @@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {

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;
Expand All @@ -134,5 +134,25 @@ TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
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

0 comments on commit 724beac

Please sign in to comment.