From: Kadir Cetinkaya Date: Wed, 24 Apr 2019 09:23:31 +0000 (+0000) Subject: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62041af5673ae85b83198872b2bc17ebd1d3668a;p=clang [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path Summary: Include insertion in clangd was inserting absolute paths when the include directory was an absolute path with a double dot. This patch makes sure double dots are handled both with absolute and relative paths. Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60873 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359078 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index a26df9a7f6..af763059ea 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/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/unittests/Lex/HeaderSearchTest.cpp b/unittests/Lex/HeaderSearchTest.cpp index b5b0f9a833..5bcdd9efd1 100644 --- a/unittests/Lex/HeaderSearchTest.cpp +++ b/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