diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index e45424a5f712a..5d8f006252fd9 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -2465,8 +2465,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs( // 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); @@ -2474,8 +2473,8 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs( 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 @@ -2483,6 +2482,17 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs( // 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. @@ -2497,17 +2507,6 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs( << "\"\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 index cc8ec9ceb89b3..4929511cd00af 100644 --- 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.