r350714 - [Driver] Fix libcxx detection on Darwin with clang run as ./clang

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 9 05:08:11 PST 2019


Author: ibiryukov
Date: Wed Jan  9 05:08:11 2019
New Revision: 350714

URL: http://llvm.org/viewvc/llvm-project?rev=350714&view=rev
Log:
[Driver] Fix libcxx detection on Darwin with clang run as ./clang

Summary:
By using '..' instead of fs::parent_path.

The intention of the code was to go from 'path/to/clang/bin' to
'path/to/clang/include'. In most cases parent_path works, however it
would fail when clang is run as './clang'.

This was noticed in Chromium's bug tracker, see
https://bugs.chromium.org/p/chromium/issues/detail?id=919761

Reviewers: arphaman, thakis, EricWF

Reviewed By: arphaman, thakis

Subscribers: christof, cfe-commits

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

Added:
    cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/
    cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/clang
Modified:
    cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
    cfe/trunk/test/Driver/darwin-stdlib.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=350714&r1=350713&r2=350714&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Jan  9 05:08:11 2019
@@ -1752,10 +1752,11 @@ void DarwinClang::AddClangCXXStdlibInclu
       break;
     // On Darwin, libc++ may be installed alongside the compiler in
     // include/c++/v1.
-    // Get from 'foo/bin' to 'foo'.
-    SmallString<128> P = llvm::sys::path::parent_path(InstallDir);
-    // Get to 'foo/include/c++/v1'.
-    llvm::sys::path::append(P, "include", "c++", "v1");
+    // Get from 'foo/bin' to 'foo/include/c++/v1'.
+    SmallString<128> P = InstallDir;
+    // Note that InstallDir can be relative, so we have to '..' and not
+    // parent_path.
+    llvm::sys::path::append(P, "..", "include", "c++", "v1");
     addSystemInclude(DriverArgs, CC1Args, P);
     break;
   }

Modified: cfe/trunk/test/Driver/darwin-stdlib.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-stdlib.cpp?rev=350714&r1=350713&r2=350714&view=diff
==============================================================================
--- cfe/trunk/test/Driver/darwin-stdlib.cpp (original)
+++ cfe/trunk/test/Driver/darwin-stdlib.cpp Wed Jan  9 05:08:11 2019
@@ -14,7 +14,7 @@
 // optional absolute include for libc++ from InitHeaderSearch.cpp also fires.
 
 // CHECK-LIBCXX: "-stdlib=libc++"
-// CHECK-LIBCXX: "-internal-isystem" "{{[^"]*}}{{/|\\\\}}Inputs{{/|\\\\}}darwin_toolchain_tree{{/|\\\\}}bin{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1"
+// CHECK-LIBCXX: "-internal-isystem" "{{[^"]*}}{{/|\\\\}}Inputs{{/|\\\\}}darwin_toolchain_tree{{/|\\\\}}bin{{/|\\\\}}..{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1"
 
 // CHECK-LIBSTDCXX-NOT: -stdlib=libc++
 // CHECK-LIBSTDCXX-NOT: -stdlib=libstdc++

Added: cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/clang
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/clang?rev=350714&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/clang (added)
+++ cfe/trunk/test/Tooling/Inputs/mock-libcxx/bin/clang Wed Jan  9 05:08:11 2019
@@ -0,0 +1 @@
+This file is a placeholder to keep its parent directory in git.




More information about the cfe-commits mailing list