[clang-tools-extra] a3b7934 - [clangd] Don't mangle workdir-relevant driver path in compile commands

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 04:47:05 PDT 2020


Author: Sam McCall
Date: 2020-06-19T13:46:55+02:00
New Revision: a3b793401255cc91cbfaa5360e0940678bf86d1d

URL: https://github.com/llvm/llvm-project/commit/a3b793401255cc91cbfaa5360e0940678bf86d1d
DIFF: https://github.com/llvm/llvm-project/commit/a3b793401255cc91cbfaa5360e0940678bf86d1d.diff

LOG: [clangd] Don't mangle workdir-relevant driver path in compile commands

Summary:
We can't resolve this (if it's a symlink) without further refactoring, but the
current behaviour is just incorrect.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/CompileCommands.cpp
    clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index a73312a521e8..a2d704f57bda 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -135,6 +135,12 @@ static std::string resolveDriver(llvm::StringRef Driver, bool FollowSymlink,
   // First, eliminate relative paths.
   std::string Storage;
   if (!llvm::sys::path::is_absolute(Driver)) {
+    // If it's working-dir relative like bin/clang, we can't resolve it.
+    // FIXME: we could if we had the working directory here.
+    // Let's hope it's not a symlink.
+    if (llvm::any_of(Driver,
+                     [](char C) { return llvm::sys::path::is_separator(C); }))
+      return Driver.str();
     // If the driver is a generic like "g++" with no path, add clang dir.
     if (ClangPath &&
         (Driver == "clang" || Driver == "clang++" || Driver == "gcc" ||

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index 839c41d93ccb..d064c941a590 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -115,7 +115,7 @@ TEST(CommandMangler, ClangPath) {
 
   Cmd = {"foo/unknown-binary", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_EQ(testPath("fake/unknown-binary"), Cmd.front());
+  EXPECT_EQ("foo/unknown-binary", Cmd.front());
 }
 
 // Only run the PATH/symlink resolving test on unix, we need to fiddle


        


More information about the cfe-commits mailing list