summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/unittests/clangd/HeadersTests.cpp5
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp7
-rw-r--r--clang/unittests/Lex/HeaderSearchTest.cpp7
3 files changed, 15 insertions, 4 deletions
diff --git a/clang-tools-extra/unittests/clangd/HeadersTests.cpp b/clang-tools-extra/unittests/clangd/HeadersTests.cpp
index c0b4d39ced7..28f4d7b1bd0 100644
--- a/clang-tools-extra/unittests/clangd/HeadersTests.cpp
+++ b/clang-tools-extra/unittests/clangd/HeadersTests.cpp
@@ -213,6 +213,11 @@ TEST_F(HeadersTest, DoNotInsertIfInSameFile) {
TEST_F(HeadersTest, ShortenedInclude) {
std::string BarHeader = testPath("sub/bar.h");
EXPECT_EQ(calculate(BarHeader), "\"bar.h\"");
+
+ SearchDirArg = (llvm::Twine("-I") + Subdir + "/..").str();
+ CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+ BarHeader = testPath("sub/bar.h");
+ EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
}
TEST_F(HeadersTest, NotShortenedInclude) {
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index a26df9a7f60..af763059ea9 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1685,11 +1685,10 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
StringRef Dir = SearchDirs[I].getDir()->getName();
llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
- if (!WorkingDir.empty() && !path::is_absolute(Dir)) {
+ if (!WorkingDir.empty() && !path::is_absolute(Dir))
fs::make_absolute(WorkingDir, DirPath);
- path::remove_dots(DirPath, /*remove_dot_dot=*/true);
- Dir = DirPath;
- }
+ path::remove_dots(DirPath, /*remove_dot_dot=*/true);
+ Dir = DirPath;
for (auto NI = path::begin(File), NE = path::end(File),
DI = path::begin(Dir), DE = path::end(Dir);
/*termination condition in loop*/; ++NI, ++DI) {
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index b5b0f9a833c..5bcdd9efd17 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -100,5 +100,12 @@ TEST_F(HeaderSearchTest, BackSlash) {
}
#endif
+TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
+ addSearchDir("/x/../y/");
+ EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z",
+ /*WorkingDir=*/""),
+ "z");
+}
+
} // namespace
} // namespace clang
OpenPOWER on IntegriCloud