This revision was automatically updated to reflect the committed changes. Closed by commit rL359078: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path (authored by kadircet, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D60873?vs=195751&id=196400#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60873/new/ https://reviews.llvm.org/D60873 Files: cfe/trunk/lib/Lex/HeaderSearch.cpp cfe/trunk/unittests/Lex/HeaderSearchTest.cpp clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Index: clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp @@ -213,6 +213,11 @@ 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) { Index: cfe/trunk/lib/Lex/HeaderSearch.cpp =================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp +++ cfe/trunk/lib/Lex/HeaderSearch.cpp @@ -1685,11 +1685,10 @@ 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) { Index: cfe/trunk/unittests/Lex/HeaderSearchTest.cpp =================================================================== --- cfe/trunk/unittests/Lex/HeaderSearchTest.cpp +++ cfe/trunk/unittests/Lex/HeaderSearchTest.cpp @@ -100,5 +100,12 @@ } #endif +TEST_F(HeaderSearchTest, DotDotsWithAbsPath) { + addSearchDir("/x/../y/"); + EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z", + /*WorkingDir=*/""), + "z"); +} + } // namespace } // namespace clang
Index: clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp @@ -213,6 +213,11 @@ 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) { Index: cfe/trunk/lib/Lex/HeaderSearch.cpp =================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp +++ cfe/trunk/lib/Lex/HeaderSearch.cpp @@ -1685,11 +1685,10 @@ 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) { Index: cfe/trunk/unittests/Lex/HeaderSearchTest.cpp =================================================================== --- cfe/trunk/unittests/Lex/HeaderSearchTest.cpp +++ cfe/trunk/unittests/Lex/HeaderSearchTest.cpp @@ -100,5 +100,12 @@ } #endif +TEST_F(HeaderSearchTest, DotDotsWithAbsPath) { + addSearchDir("/x/../y/"); + EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z", + /*WorkingDir=*/""), + "z"); +} + } // namespace } // namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits