Skip to content

Commit

Permalink
[clang][HeaderSearch] Make sure there are no backslashes in suggested…
Browse files Browse the repository at this point in the history
…Path

Reviewers: sammccall

Differential Revision: https://reviews.llvm.org/D60995

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359075 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kadircet committed Apr 24, 2019
1 parent 418eae9 commit cb27266
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 6 additions & 4 deletions include/clang/Lex/HeaderSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,18 @@ class HeaderSearch {
/// Retrieve a uniqued framework name.
StringRef getUniqueFrameworkName(StringRef Framework);

/// Suggest a path by which the specified file could be found, for
/// use in diagnostics to suggest a #include.
/// Suggest a path by which the specified file could be found, for use in
/// diagnostics to suggest a #include. Returned path will only contain forward
/// slashes as separators.
///
/// \param IsSystem If non-null, filled in to indicate whether the suggested
/// path is relative to a system header directory.
std::string suggestPathToFileForDiagnostics(const FileEntry *File,
bool *IsSystem = nullptr);

/// Suggest a path by which the specified file could be found, for
/// use in diagnostics to suggest a #include.
/// Suggest a path by which the specified file could be found, for use in
/// diagnostics to suggest a #include. Returned path will only contain forward
/// slashes as separators.
///
/// \param WorkingDir If non-empty, this will be prepended to search directory
/// paths that are relative.
Expand Down
2 changes: 1 addition & 1 deletion lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,5 +1720,5 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(

if (IsSystem)
*IsSystem = BestPrefixLength ? BestSearchDir >= SystemDirIdx : false;
return File.drop_front(BestPrefixLength);
return path::convert_to_slash(File.drop_front(BestPrefixLength));
}
9 changes: 9 additions & 0 deletions unittests/Lex/HeaderSearchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,14 @@ TEST_F(HeaderSearchTest, Dots) {
"z");
}

#ifdef _WIN32
TEST_F(HeaderSearchTest, BackSlash) {
addSearchDir("C:\\x\\y\\");
EXPECT_EQ(Search.suggestPathToFileForDiagnostics("C:\\x\\y\\z\\t",
/*WorkingDir=*/""),
"z/t");
}
#endif

} // namespace
} // namespace clang

0 comments on commit cb27266

Please sign in to comment.