r359078 - [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 02:23:31 PDT 2019


Author: kadircet
Date: Wed Apr 24 02:23:31 2019
New Revision: 359078

URL: http://llvm.org/viewvc/llvm-project?rev=359078&view=rev
Log:
[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

Modified:
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/unittests/Lex/HeaderSearchTest.cpp

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Apr 24 02:23:31 2019
@@ -1685,11 +1685,10 @@ std::string HeaderSearch::suggestPathToF
 
     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) {

Modified: cfe/trunk/unittests/Lex/HeaderSearchTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/HeaderSearchTest.cpp?rev=359078&r1=359077&r2=359078&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/HeaderSearchTest.cpp (original)
+++ cfe/trunk/unittests/Lex/HeaderSearchTest.cpp Wed Apr 24 02:23:31 2019
@@ -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




More information about the cfe-commits mailing list