diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -432,4 +432,9 @@ "specify a MSP430 device, or -mhwmult to set hardware multiply type " "explicitly.">, InGroup; +def warn_drv_libstdcxx_not_found : Warning< + "include path for libstdc++ headers not found; pass '-stdlib=libc++' on the " + "command line to use the libc++ standard library instead">, + InGroup>; + } diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -232,11 +232,6 @@ def warn_option_invalid_ocl_version : Warning< "OpenCL version %0 does not support the option '%1'">, InGroup; -def warn_stdlibcxx_not_found : Warning< - "include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the " - "command line to use the libc++ standard library instead">, - InGroup>; - def err_builtin_needs_feature : Error<"%0 needs target feature %1">; def err_function_needs_feature : Error< "always_inline function %1 requires target feature '%2', but would " diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -503,6 +503,9 @@ const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; @@ -529,6 +532,13 @@ llvm::opt::ArgStringList &CmdArgs, StringRef Sanitizer, bool shared = true) const; + + bool AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + llvm::SmallString<128> Base, + llvm::StringRef Version, + llvm::StringRef ArchDir, + llvm::StringRef BitDir) const; }; } // end namespace toolchains 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 @@ -11,6 +11,7 @@ #include "CommonArgs.h" #include "clang/Basic/AlignedAllocation.h" #include "clang/Basic/ObjCRuntime.h" +#include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" @@ -1804,6 +1805,84 @@ } } +void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + + llvm::StringRef Sysroot = "/"; + if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot)) + Sysroot = A->getValue(); + + bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc); + bool NoStdlibInc = DriverArgs.hasArg(options::OPT_nostdlibinc); + bool NoBuiltinInc = DriverArgs.hasArg(options::OPT_nobuiltininc); + + // Add /usr/local/include + if (!NoStdInc && !NoStdlibInc) { + SmallString<128> P(Sysroot); + llvm::sys::path::append(P, "usr", "local", "include"); + addSystemInclude(DriverArgs, CC1Args, P); + } + + // Add the Clang builtin headers (/include) + if (!NoStdInc && !NoBuiltinInc) { + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, "include"); + addSystemInclude(DriverArgs, CC1Args, P); + } + + if (NoStdInc || NoStdlibInc) + return; + + // Check for configure-time C include directories. + llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); + if (!CIncludeDirs.empty()) { + llvm::SmallVector dirs; + CIncludeDirs.split(dirs, ":"); + for (llvm::StringRef dir : dirs) { + llvm::StringRef Prefix = + llvm::sys::path::is_absolute(dir) ? llvm::StringRef(Sysroot) : ""; + addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + } + } else { + // Otherwise, add /usr/include. + SmallString<128> P(Sysroot); + llvm::sys::path::append(P, "usr", "include"); + addExternCSystemInclude(DriverArgs, CC1Args, P.str()); + } +} + +bool DarwinClang::AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args, + llvm::SmallString<128> Base, + llvm::StringRef Version, + llvm::StringRef ArchDir, + llvm::StringRef BitDir) const { + llvm::sys::path::append(Base, Version); + + // Add the base dir + addSystemInclude(DriverArgs, CC1Args, Base); + + // Add the multilib dirs + { + llvm::SmallString<128> P = Base; + if (!ArchDir.empty()) + llvm::sys::path::append(P, ArchDir); + if (!BitDir.empty()) + llvm::sys::path::append(P, BitDir); + addSystemInclude(DriverArgs, CC1Args, P); + } + + // Add the backward dir + { + llvm::SmallString<128> P = Base; + llvm::sys::path::append(P, "backward"); + addSystemInclude(DriverArgs, CC1Args, P); + } + + return getVFS().exists(Base); +} + void DarwinClang::AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { @@ -1811,29 +1890,95 @@ // CC1Args. // FIXME: this should not be necessary, remove usages in the frontend // (e.g. HeaderSearchOptions::UseLibcxx) and don't pipe -stdlib. + // Also check whether this is used for setting library search paths. ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args); if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; + llvm::SmallString<128> Sysroot; + if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot)) { + Sysroot = A->getValue(); + } else { + Sysroot = "/"; + } + switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: { - llvm::StringRef InstallDir = getDriver().getInstalledDir(); - if (InstallDir.empty()) - break; - // On Darwin, libc++ may be installed alongside the compiler in - // 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); + // On Darwin, libc++ is installed alongside the compiler in + // include/c++/v1, so get from '/bin' to '/include/c++/v1'. + { + llvm::SmallString<128> P = llvm::StringRef(getDriver().getInstalledDir()); + // Note that P can be relative, so we have to '..' and not parent_path. + llvm::sys::path::append(P, "..", "include", "c++", "v1"); + addSystemInclude(DriverArgs, CC1Args, P); + } + // Also add /usr/include/c++/v1 unless -nostdinc is used, + // to match the legacy behavior in CC1. + if (!DriverArgs.hasArg(options::OPT_nostdinc)) { + llvm::SmallString<128> P = Sysroot; + llvm::sys::path::append(P, "usr", "include", "c++", "v1"); + addSystemInclude(DriverArgs, CC1Args, P); + } break; } + case ToolChain::CST_Libstdcxx: - // FIXME: should we do something about it? + llvm::SmallString<128> UsrIncludeCxx = Sysroot; + llvm::sys::path::append(UsrIncludeCxx, "usr", "include", "c++"); + + llvm::Triple::ArchType arch = getTriple().getArch(); + bool IsBaseFound = true; + switch (arch) { + default: break; + + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.2.1", + "powerpc-apple-darwin10", + arch == llvm::Triple::ppc64 ? "ppc64" : ""); + IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.0.0", "powerpc-apple-darwin10", + arch == llvm::Triple::ppc64 ? "ppc64" : ""); + break; + + case llvm::Triple::x86: + case llvm::Triple::x86_64: + IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.2.1", + "i686-apple-darwin10", + arch == llvm::Triple::x86_64 ? "x86_64" : ""); + IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.0.0", "i686-apple-darwin8", + ""); + break; + + case llvm::Triple::arm: + case llvm::Triple::thumb: + IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.2.1", + "arm-apple-darwin10", + "v7"); + IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.2.1", + "arm-apple-darwin10", + "v6"); + break; + + case llvm::Triple::aarch64: + IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, + "4.2.1", + "arm64-apple-darwin10", + ""); + break; + } + + if (!IsBaseFound) { + getDriver().Diag(diag::warn_drv_libstdcxx_not_found); + } + break; } } diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp --- a/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/clang/lib/Frontend/InitHeaderSearch.cpp @@ -210,6 +210,10 @@ const HeaderSearchOptions &HSOpts) { llvm::Triple::OSType os = triple.getOS(); + if (triple.isOSDarwin()) { + llvm_unreachable("Include management is handled in the driver."); + } + if (HSOpts.UseStandardSystemIncludes) { switch (os) { case llvm::Triple::CloudABI: @@ -365,49 +369,7 @@ // FIXME: temporary hack: hard-coded paths. if (triple.isOSDarwin()) { - bool IsBaseFound = true; - switch (triple.getArch()) { - default: break; - - case llvm::Triple::ppc: - case llvm::Triple::ppc64: - IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", - "powerpc-apple-darwin10", "", - "ppc64", triple); - IsBaseFound |= AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", - "powerpc-apple-darwin10", "", - "ppc64", triple); - break; - - case llvm::Triple::x86: - case llvm::Triple::x86_64: - IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", - "i686-apple-darwin10", "", - "x86_64", triple); - IsBaseFound |= AddGnuCPlusPlusIncludePaths( - "/usr/include/c++/4.0.0", "i686-apple-darwin8", "", "", triple); - break; - - case llvm::Triple::arm: - case llvm::Triple::thumb: - IsBaseFound = AddGnuCPlusPlusIncludePaths( - "/usr/include/c++/4.2.1", "arm-apple-darwin10", "v7", "", triple); - IsBaseFound |= AddGnuCPlusPlusIncludePaths( - "/usr/include/c++/4.2.1", "arm-apple-darwin10", "v6", "", triple); - break; - - case llvm::Triple::aarch64: - IsBaseFound = AddGnuCPlusPlusIncludePaths( - "/usr/include/c++/4.2.1", "arm64-apple-darwin10", "", "", triple); - break; - } - // Warn when compiling pure C++ / Objective-C++ only. - if (!IsBaseFound && - !(LangOpts.CUDA || LangOpts.OpenCL || LangOpts.RenderScript)) { - Headers.getDiags().Report(SourceLocation(), - diag::warn_stdlibcxx_not_found); - } - return; + llvm_unreachable("Include management is handled in the driver."); } switch (os) { @@ -464,6 +426,16 @@ break; } + // All header search logic is handled in the Driver for Darwin. + if (triple.isOSDarwin()) { + if (HSOpts.UseStandardSystemIncludes) { + // Add the default framework include paths on Darwin. + AddPath("/System/Library/Frameworks", System, true); + AddPath("/Library/Frameworks", System, true); + } + return; + } + if (Lang.CPlusPlus && !Lang.AsmPreprocessor && HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) { if (HSOpts.UseLibcxx) { @@ -474,14 +446,6 @@ } AddDefaultCIncludePaths(triple, HSOpts); - - // Add the default framework include paths on Darwin. - if (HSOpts.UseStandardSystemIncludes) { - if (triple.isOSDarwin()) { - AddPath("/System/Library/Frameworks", System, true); - AddPath("/Library/Frameworks", System, true); - } - } } /// RemoveDuplicates - If there are duplicate directory entries in the specified diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_aarch64/usr/include/c++/4.2.1/arm64-apple-darwin10/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_aarch64/usr/include/c++/4.2.1/arm64-apple-darwin10/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_aarch64/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_aarch64/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/include/c++/4.2.1/arm-apple-darwin10/v6/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/include/c++/4.2.1/arm-apple-darwin10/v6/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/include/c++/4.2.1/arm-apple-darwin10/v7/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/include/c++/4.2.1/arm-apple-darwin10/v7/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_arm/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/include/c++/4.0.0/powerpc-apple-darwin10/ppc64/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/include/c++/4.0.0/powerpc-apple-darwin10/ppc64/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/include/c++/4.2.1/powerpc-apple-darwin10/ppc64/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/include/c++/4.2.1/powerpc-apple-darwin10/ppc64/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_ppc/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/include/c++/4.0.0/i686-apple-darwin8/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/include/c++/4.0.0/i686-apple-darwin8/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_libstdcxx_x86/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_no_libcxx/usr/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_no_libcxx/usr/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_no_libcxx/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_no_libcxx/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_no_libstdcxx/usr/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_no_libstdcxx/usr/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_no_libstdcxx/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_no_libstdcxx/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr/usr/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr/usr/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/local/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/local/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/local/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_and_usr_local/usr/local/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_local/usr/local/include/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_local/usr/local/include/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_sdk_usr_local/usr/local/lib/.keep b/clang/test/Driver/Inputs/basic_darwin_sdk_usr_local/usr/local/lib/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_toolchain/usr/bin/.keep b/clang/test/Driver/Inputs/basic_darwin_toolchain/usr/bin/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_toolchain/usr/include/c++/v1/.keep b/clang/test/Driver/Inputs/basic_darwin_toolchain/usr/include/c++/v1/.keep new file mode 100644 diff --git a/clang/test/Driver/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin/.keep b/clang/test/Driver/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin/.keep new file mode 100644 diff --git a/clang/test/Driver/darwin-header-search-libcxx.cpp b/clang/test/Driver/darwin-header-search-libcxx.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Driver/darwin-header-search-libcxx.cpp @@ -0,0 +1,78 @@ +// General tests that the header search paths for libc++ detected by the driver +// and passed to CC1 are correct on Darwin platforms. + +// Check without a sysroot and without headers alongside the installation +// (no include path should be added, and no warning or error). +// +// 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_no_libcxx/usr/bin \ +// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-NONE %s +// CHECK-LIBCXX-NONE: "{{[^"]*}}clang{{[^"]*}}" "-cc1" + +// Check with only headers alongside the installation (those should be used, +// but we should still add /usr/include/c++/v1 after to preserve legacy). +// +// 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: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain --check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s +// CHECK-LIBCXX-TOOLCHAIN-1: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" +// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" "/usr/include/c++/v1" +// +// 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: -isysroot %S/Inputs/basic_darwin_sdk_no_libcxx \ +// RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain --check-prefix=CHECK-LIBCXX-TOOLCHAIN-2 %s +// CHECK-LIBCXX-TOOLCHAIN-2: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBCXX-TOOLCHAIN-2: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" + +// Check with both headers in the sysroot and headers alongside the installation +// (the headers in should be added after the toolchain headers). +// +// 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: -isysroot %S/Inputs/basic_darwin_sdk_usr \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ +// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ +// RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s +// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" +// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" + +// Make sure that using -nostdinc or -nostdlibinc will drop the non-toolchain +// C++ library include paths (so all except /usr/bin/../include/c++/v1). +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr \ +// RUN: -nostdinc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \ +// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \ +// RUN: --check-prefix=CHECK-LIBCXX-NOSTDINC %s +// CHECK-LIBCXX-NOSTDINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBCXX-NOSTDINC: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" +// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr \ +// 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 +// CHECK-LIBCXX-NOSTDLIBINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBCXX-NOSTDLIBINC: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1" +// CHECK-LIBCXX-NOSTDLIBINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" diff --git a/clang/test/Driver/darwin-header-search-libstdcxx.cpp b/clang/test/Driver/darwin-header-search-libstdcxx.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Driver/darwin-header-search-libstdcxx.cpp @@ -0,0 +1,118 @@ +// General tests that the header search paths for libstdc++ detected by the +// driver and passed to CC1 are correct on Darwin platforms. + +// Check ppc and ppc64 +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target ppc-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_ppc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_ppc --check-prefix=CHECK-LIBSTDCXX-PPC %s +// CHECK-LIBSTDCXX-PPC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1 +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/powerpc-apple-darwin10" +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0" +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/powerpc-apple-darwin10" +// CHECK-LIBSTDCXX-PPC: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/backward" +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target ppc64-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_ppc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_ppc --check-prefix=CHECK-LIBSTDCXX-PPC64 %s +// CHECK-LIBSTDCXX-PPC64: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/powerpc-apple-darwin10/ppc64" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/powerpc-apple-darwin10/ppc64" +// CHECK-LIBSTDCXX-PPC64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/backward" + +// Check x86 and x86_64 +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target i686-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_x86 \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_x86 --check-prefix=CHECK-LIBSTDCXX-X86 %s +// CHECK-LIBSTDCXX-X86: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/i686-apple-darwin10" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/i686-apple-darwin8" +// CHECK-LIBSTDCXX-X86: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/backward" +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_x86 \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_x86 --check-prefix=CHECK-LIBSTDCXX-X86_64 %s +// CHECK-LIBSTDCXX-X86_64: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/i686-apple-darwin8" +// CHECK-LIBSTDCXX-X86_64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.0.0/backward" + +// Check arm and thumb +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target arm-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_arm \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_arm --check-prefix=CHECK-LIBSTDCXX-ARM %s +// CHECK-LIBSTDCXX-ARM: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/arm-apple-darwin10/v7" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/arm-apple-darwin10/v6" +// CHECK-LIBSTDCXX-ARM: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target arm-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_arm \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_arm --check-prefix=CHECK-LIBSTDCXX-THUMB %s +// CHECK-LIBSTDCXX-THUMB: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/arm-apple-darwin10/v7" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/arm-apple-darwin10/v6" +// CHECK-LIBSTDCXX-THUMB: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" + +// Check aarch64 +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target arm64-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_libstdcxx_aarch64 \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_libstdcxx_aarch64 --check-prefix=CHECK-LIBSTDCXX-AARCH64 %s +// CHECK-LIBSTDCXX-AARCH64: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-LIBSTDCXX-AARCH64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1" +// CHECK-LIBSTDCXX-AARCH64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/arm64-apple-darwin10" +// CHECK-LIBSTDCXX-AARCH64: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/4.2.1/backward" + +// Make sure we issue a warning when we can't find the path +// +// RUN: %clang -no-canonical-prefixes %s -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -stdlib=libstdc++ \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libstdcxx \ +// RUN: | FileCheck --check-prefix=CHECK-LIBSTDCXX-MISSING %s +// CHECK-LIBSTDCXX-MISSING: clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead +// +// RUN: %clang %s -target x86_64-apple-darwin -fsyntax-only 2>&1 \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libstdcxx \ +// RUN: -stdlib=libc++ \ +// RUN: | FileCheck -allow-empty --check-prefix=CHECK-LIBSTDCXX-MISSING-1 %s +// CHECK-LIBSTDCXX-MISSING-1-NOT: warning +// +// RUN: %clang %s -target x86_64-apple-darwin -fsyntax-only 2>&1 \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libstdcxx \ +// RUN: | FileCheck -allow-empty --check-prefix=CHECK-LIBSTDCXX-MISSING-2 %s +// CHECK-LIBSTDCXX-MISSING-2-NOT: warning diff --git a/clang/test/Driver/darwin-header-search-system.cpp b/clang/test/Driver/darwin-header-search-system.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Driver/darwin-header-search-system.cpp @@ -0,0 +1,80 @@ +// General tests that the system header search paths detected by the driver +// and passed to CC1 are correct on Darwin platforms. + +// Check system headers (everything below and ) +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -DRESOURCE=%S/Inputs/resource_dir \ +// RUN: --check-prefix=CHECK-SYSTEM %s +// CHECK-SYSTEM: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-SYSTEM: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-SYSTEM: "-internal-isystem" "[[RESOURCE]]/include" +// CHECK-SYSTEM: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" + +// Make sure that using -nobuiltininc will drop resource headers +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -nobuiltininc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -DRESOURCE=%S/Inputs/resource_dir \ +// RUN: --check-prefix=CHECK-NOBUILTININC %s +// CHECK-NOBUILTININC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-NOBUILTININC: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-NOBUILTININC-NOT: "-internal-isystem" "[[RESOURCE]]/include" +// CHECK-NOBUILTININC: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" + +// Make sure that using -nostdlibinc will drop /usr/local/include and +// /usr/include. +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -nostdlibinc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -DRESOURCE=%S/Inputs/resource_dir \ +// RUN: --check-prefix=CHECK-NOSTDLIBINC %s +// CHECK-NOSTDLIBINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-NOSTDLIBINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-NOSTDLIBINC: "-internal-isystem" "[[RESOURCE]]/include" +// CHECK-NOSTDLIBINC-NOT: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" + +// Make sure that -nostdinc drops all the system include paths, including +// /include. +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -nostdinc \ +// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_and_usr_local \ +// RUN: -DRESOURCE=%S/Inputs/resource_dir \ +// RUN: --check-prefix=CHECK-NOSTDINC %s +// CHECK-NOSTDINC: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-NOSTDINC-NOT: "-internal-isystem" "[[RESOURCE]]/include" +// CHECK-NOSTDINC-NOT: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" + +// Check search paths without -isysroot +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-apple-darwin \ +// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck -DRESOURCE=%S/Inputs/resource_dir \ +// RUN: --check-prefix=CHECK-NOSYSROOT %s +// CHECK-NOSYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-NOSYSROOT: "-internal-isystem" "/usr/local/include" +// CHECK-NOSYSROOT: "-internal-isystem" "[[RESOURCE]]/include" +// CHECK-NOSYSROOT: "-internal-externc-isystem" "/usr/include" diff --git a/clang/test/Driver/darwin-stdlib.cpp b/clang/test/Driver/darwin-stdlib.cpp --- a/clang/test/Driver/darwin-stdlib.cpp +++ b/clang/test/Driver/darwin-stdlib.cpp @@ -9,13 +9,6 @@ // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %S/Inputs/darwin_toolchain_tree/bin/ -arch armv7s -miphoneos-version-min=7.0 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LIBCXX // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %S/Inputs/darwin_toolchain_tree/bin/ -arch armv7k %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LIBCXX -// The purpose of this test is that the libc++ headers should be found -// properly. We also pass -stdlib=libc++ to make sure the logic to add the -// 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-LIBSTDCXX-NOT: -stdlib=libc++ // CHECK-LIBSTDCXX-NOT: -stdlib=libstdc++ -// CHECK-LIBSTDCXX-NOT: -internal-isystem diff --git a/clang/test/Frontend/warning-stdlibcxx-darwin.cpp b/clang/test/Frontend/warning-stdlibcxx-darwin.cpp deleted file mode 100644 --- a/clang/test/Frontend/warning-stdlibcxx-darwin.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s 2>&1 | FileCheck %s -// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist -stdlib=libc++ %s -verify -// RUN: %clang -cc1 -x c++-cpp-output -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s -verify -// CHECK: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead - -// expected-no-diagnostics