Index: lib/Driver/ToolChain.cpp =================================================================== --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -548,16 +548,23 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ ToolChain::CXXStdlibType Type; bool HasValidType = false; + bool ForcePlatformDefault = false; const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); if (A) { - HasValidType = ParseCXXStdlibType(A->getValue(), Type); - if (!HasValidType) + StringRef Value = A->getValue(); + HasValidType = ParseCXXStdlibType(Value, Type); + + // Only use in tests to override CLANG_DEFAULT_CXX_STDLIB! + if (Value == "platform") + ForcePlatformDefault = true; + else if (!HasValidType) getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } - if (!HasValidType && !ParseCXXStdlibType(CLANG_DEFAULT_CXX_STDLIB, Type)) + if (!HasValidType && (ForcePlatformDefault || + !ParseCXXStdlibType(CLANG_DEFAULT_CXX_STDLIB, Type))) Type = GetDefaultCXXStdlibType(); return Type; Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -728,7 +728,7 @@ bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } - CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; + CXXStdlibType GetDefaultCXXStdlibType() const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; @@ -756,7 +756,7 @@ bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } - CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; + CXXStdlibType GetDefaultCXXStdlibType() const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -3106,16 +3106,7 @@ getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); } -ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { - if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { - StringRef Value = A->getValue(); - if (Value == "libstdc++") - return ToolChain::CST_Libstdcxx; - if (Value == "libc++") - return ToolChain::CST_Libcxx; - - getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); - } +ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { if (getTriple().getOSMajorVersion() >= 10) return ToolChain::CST_Libcxx; return ToolChain::CST_Libstdcxx; @@ -3258,17 +3249,7 @@ Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } -ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { - if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { - StringRef Value = A->getValue(); - if (Value == "libstdc++") - return ToolChain::CST_Libstdcxx; - if (Value == "libc++") - return ToolChain::CST_Libcxx; - - getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); - } - +ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { unsigned Major, Minor, Micro; getTriple().getOSVersion(Major, Minor, Micro); if (Major >= 7 || Major == 0) { Index: test/Driver/freebsd.cpp =================================================================== --- test/Driver/freebsd.cpp +++ test/Driver/freebsd.cpp @@ -1,13 +1,13 @@ -// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd10.0 2>&1 \ +// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-TEN %s -// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd9.2 2>&1 \ +// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd9.2 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NINE %s // CHECK-TEN: "-lc++" "-lm" // CHECK-NINE: "-lstdc++" "-lm" -// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd10.0 2>&1 \ +// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG-TEN %s -// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd9.2 2>&1 \ +// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd9.2 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG-NINE %s // CHECK-PG-TEN: "-lc++_p" "-lm_p" // CHECK-PG-NINE: "-lstdc++_p" "-lm_p" Index: test/Driver/netbsd.cpp =================================================================== --- test/Driver/netbsd.cpp +++ test/Driver/netbsd.cpp @@ -1,93 +1,93 @@ // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=X86_64 %s // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd7.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=X86_64-7 %s // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd6.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=X86_64-6 %s // RUN: %clangxx -no-canonical-prefixes -target arm--netbsd6.0.0-eabi \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=ARM %s // RUN: %clangxx -no-canonical-prefixes -target arm--netbsd7.0.0-eabi \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=ARM-7 %s // RUN: %clangxx -no-canonical-prefixes -target aarch64--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=AARCH64 %s // RUN: %clangxx -no-canonical-prefixes -target aarch64--netbsd7.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=AARCH64-7 %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd6.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC-6 %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd7.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC-7 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC64 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd6.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC64-6 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd7.0.0 \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=SPARC64-7 %s // RUN: %clangxx -no-canonical-prefixes -target powerpc--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=POWERPC %s // RUN: %clangxx -no-canonical-prefixes -target powerpc64--netbsd \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=POWERPC64 %s // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-X86_64 %s // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd7.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-X86_64-7 %s // RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd6.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-X86_64-6 %s // RUN: %clangxx -no-canonical-prefixes -target arm--netbsd6.0.0-eabi -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-ARM %s // RUN: %clangxx -no-canonical-prefixes -target arm--netbsd7.0.0-eabi -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-ARM-7 %s // RUN: %clangxx -no-canonical-prefixes -target aarch64--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-AARCH64 %s // RUN: %clangxx -no-canonical-prefixes -target aarch64--netbsd7.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-AARCH64-7 %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd6.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC-6 %s // RUN: %clangxx -no-canonical-prefixes -target sparc--netbsd7.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC-7 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC64 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd6.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC64-6 %s // RUN: %clangxx -no-canonical-prefixes -target sparc64--netbsd7.0.0 -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-SPARC64-7 %s // RUN: %clangxx -no-canonical-prefixes -target powerpc--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-POWERPC %s // RUN: %clangxx -no-canonical-prefixes -target powerpc64--netbsd -static \ -// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-POWERPC64 %s // X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd"