]> granicus.if.org Git - clang/commitdiff
[Driver] Fix libcxx detection on Darwin with clang run as ./clang
authorIlya Biryukov <ibiryukov@google.com>
Wed, 9 Jan 2019 13:08:11 +0000 (13:08 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Wed, 9 Jan 2019 13:08:11 +0000 (13:08 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350714 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Darwin.cpp
test/Driver/darwin-stdlib.cpp
test/Tooling/Inputs/mock-libcxx/bin/clang [new file with mode: 0644]

index 4e306fd960ecdb053ad92d2600d536af83051eed..50ecd13e6989feeb9735e9da8d16f7d4311eae50 100644 (file)
@@ -1752,10 +1752,11 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
       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;
   }
index 3da92a26ee5d487951627e570c48b65f34d04211..3e89bd1ec99fe233ffba705a2c66b9298d882064 100644 (file)
@@ -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++
diff --git a/test/Tooling/Inputs/mock-libcxx/bin/clang b/test/Tooling/Inputs/mock-libcxx/bin/clang
new file mode 100644 (file)
index 0000000..ed34c1f
--- /dev/null
@@ -0,0 +1 @@
+This file is a placeholder to keep its parent directory in git.