[PATCH] D61032: [clang] Avoid defining duplicate header search paths for libc++ on Darwin

Louis Dionne via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 11:24:36 PDT 2019


ldionne created this revision.
ldionne added a reviewer: jfb.
Herald added a reviewer: EricWF.
Herald added subscribers: cfe-commits, dexonsmith, jkorous.
Herald added a project: clang.

Before this patch, we would add both <toolchain>/usr/include/c++/v1
and /usr/include/c++/v1 to the header search paths for C++. The
toolchain path is added by the Driver and the /usr/include path
was added in CC1, a remnant of the non-refactoring of search paths
on Darwin. This patch removes /usr/include/c++/v1, since we should
be only looking for the libc++ headers beside the toolchain on Darwin.

The patch also adds basic tests validating that the right -internal-isystem
is passed from the Driver to CC1 for libc++. Once we refactor the rest of
the header search logic to be passed as -internal-isystem from the Driver
to CC1, we can add more tests to check that e.g. C headers are taken from
the SDK, etc..


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61032

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Frontend/InitHeaderSearch.cpp
  clang/test/Driver/Inputs/basic_darwin_sdk/usr/bin/.keep
  clang/test/Driver/Inputs/basic_darwin_sdk/usr/include/.keep
  clang/test/Driver/Inputs/basic_darwin_sdk/usr/lib/.keep
  clang/test/Driver/Inputs/basic_darwin_toolchain/usr/bin/.keep
  clang/test/Driver/Inputs/basic_darwin_toolchain/usr/include/c++/v1/.keep
  clang/test/Driver/darwin-header-search.cpp


Index: clang/test/Driver/darwin-header-search.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/darwin-header-search.cpp
@@ -0,0 +1,23 @@
+// General tests that the header search paths detected by the driver and passed
+// to CC1 are sane on Darwin platforms.
+
+// Check a basic invocation (the headers alongside the toolchain should be used).
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-apple-darwin \
+// RUN:     -stdlib=libc++ \
+// RUN:     -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN:     -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck -DINPUTS=%S/Inputs --check-prefix=CHECK-BASIC-LIBCXX-ISYSTEM %s
+// CHECK-BASIC-LIBCXX-ISYSTEM: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXX-ISYSTEM: "-internal-isystem" "[[INPUTS]]/basic_darwin_toolchain/usr/bin/../include/c++/v1"
+
+// Check with a custom -isysroot (the headers in the toolchain should still be used).
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-apple-darwin \
+// RUN:     -stdlib=libc++ \
+// RUN:     -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN:     -resource-dir=%S/Inputs/resource_dir \
+// RUN:     --sysroot=%S/Inputs/basic_darwin_sdk \
+// RUN:   | FileCheck -DINPUTS=%S/Inputs --check-prefix=CHECK-BASIC-LIBCXX-ISYSTEM-WITH-SYSROOT %s
+// CHECK-BASIC-LIBCXX-ISYSTEM-WITH-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXX-ISYSTEM-WITH-SYSROOT: "-internal-isystem" "[[INPUTS]]/basic_darwin_toolchain/usr/bin/../include/c++/v1"
Index: clang/lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- clang/lib/Frontend/InitHeaderSearch.cpp
+++ clang/lib/Frontend/InitHeaderSearch.cpp
@@ -467,7 +467,10 @@
   if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
       HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
     if (HSOpts.UseLibcxx) {
-      AddPath("/usr/include/c++/v1", CXXSystem, false);
+      // On Darwin, all libc++ header search paths are handled in the driver.
+      if (!triple.isOSDarwin()) {
+        AddPath("/usr/include/c++/v1", CXXSystem, false);
+      }
     } else {
       AddDefaultCPlusPlusIncludePaths(Lang, triple, HSOpts);
     }
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1778,7 +1778,7 @@
     llvm::StringRef InstallDir = getDriver().getInstalledDir();
     if (InstallDir.empty())
       break;
-    // On Darwin, libc++ may be installed alongside the compiler in
+    // On Darwin, libc++ is installed alongside the compiler in
     // include/c++/v1.
     // Get from 'foo/bin' to 'foo/include/c++/v1'.
     SmallString<128> P = InstallDir;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61032.196290.patch
Type: text/x-patch
Size: 2926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190423/1a5ca3a2/attachment.bin>


More information about the cfe-commits mailing list