diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -2463,8 +2463,7 @@ // Also check whether this is used for setting library search paths. ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args); - if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc, - options::OPT_nostdincxx)) + if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdincxx)) return; llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs); @@ -2472,8 +2471,8 @@ switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: { // On Darwin, libc++ can be installed in one of the following two places: - // 1. Alongside the compiler in /include/c++/v1 - // 2. In a SDK (or a custom sysroot) in /usr/include/c++/v1 + // 1. In a SDK (or a custom sysroot) in /usr/include/c++/v1 + // 2. Alongside the compiler in /include/c++/v1 // // The precendence of paths is as listed above, i.e. we take the first path // that exists. Also note that we never include libc++ twice -- we take the @@ -2481,6 +2480,17 @@ // include_next could break). // Check for (1) + llvm::SmallString<128> SysrootUsr = Sysroot; + llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1"); + if (getVFS().exists(SysrootUsr)) { + addSystemInclude(DriverArgs, CC1Args, SysrootUsr); + return; + } else if (DriverArgs.hasArg(options::OPT_v)) { + llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr + << "\"\n"; + } + + // Otherwise, check for (2) // Get from '/bin' to '/include/c++/v1'. // Note that InstallBin can be relative, so we use '..' instead of // parent_path. @@ -2495,17 +2505,6 @@ << "\"\n"; } - // Otherwise, check for (2) - llvm::SmallString<128> SysrootUsr = Sysroot; - llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1"); - if (getVFS().exists(SysrootUsr)) { - addSystemInclude(DriverArgs, CC1Args, SysrootUsr); - return; - } else if (DriverArgs.hasArg(options::OPT_v)) { - llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr - << "\"\n"; - } - // Otherwise, don't add any path. break; } diff --git a/clang/test/Driver/darwin-header-search-libcxx.cpp b/clang/test/Driver/darwin-header-search-libcxx.cpp --- a/clang/test/Driver/darwin-header-search-libcxx.cpp +++ b/clang/test/Driver/darwin-header-search-libcxx.cpp @@ -53,7 +53,7 @@ // CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" // Check with both headers in the sysroot and headers alongside the installation -// (the headers in the toolchain should be preferred over the headers). +// (the headers should be preferred over the headers in the toolchain). // Ensure that both -isysroot and --sysroot work, and that isysroot has precedence // over --sysroot. // @@ -89,10 +89,10 @@ // RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s // // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1" -// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" -// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" -// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the toolchain +// Make sure that using -nostdinc++ or -nostdlib will drop both the toolchain // C++ include path and the sysroot one. // // RUN: %clang -### %s -fsyntax-only 2>&1 \ @@ -104,9 +104,9 @@ // RUN: -nostdinc \ // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ -// RUN: --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s +// RUN: --check-prefix=CHECK-LIBCXX-NOSTDINC %s // CHECK-LIBCXX-NOSTDINC: "-cc1" -// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" +// CHECK-LIBCXX-NOSTDINC: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" // CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" // // RUN: %clang -### %s -fsyntax-only 2>&1 \ @@ -157,8 +157,8 @@ // RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \ // RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \ // RUN: --check-prefix=CHECK-LIBCXX-MISSING-BOTH %s -// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" // CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" // Make sure that on Darwin, we use libc++ header search paths by default even when // -stdlib= isn't passed.