Driver: Factor out some code for handling the C++ standard library.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113890 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 94c1c6b..0f63046 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -174,3 +174,28 @@
return ComputeLLVMTriple(Args);
}
+ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
+ return ToolChain::CST_Libstdcxx;
+}
+
+void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ CXXStdlibType Type = GetCXXStdlibType(Args);
+
+ switch (Type) {
+ case ToolChain::CST_Libstdcxx:
+ // Currently handled by the mass of goop in InitHeaderSearch.
+ break;
+ }
+}
+
+void ToolChain::AddClangCXXStdlibLibArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ CXXStdlibType Type = GetCXXStdlibType(Args);
+
+ switch (Type) {
+ case ToolChain::CST_Libstdcxx:
+ CmdArgs.push_back("-lstdc++");
+ break;
+ }
+}
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 20457f4..8e526e6 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -230,6 +230,11 @@
Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
+ // Add C++ include arguments, if needed.
+ types::ID InputType = Inputs[0].getType();
+ if (types::isCXX(InputType))
+ getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
+
// Add -Wp, and -Xassembler if using the preprocessor.
// FIXME: There is a very unfortunate problem here, some troubled
@@ -2503,10 +2508,8 @@
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
- // FIXME: g++ is more complicated here, it tries to put -lstdc++
- // before -lm, for example.
if (getToolChain().getDriver().CCCIsCXX)
- CmdArgs.push_back("-lstdc++");
+ getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
// link_ssp spec is empty.
@@ -2797,7 +2800,7 @@
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
if (D.CCCIsCXX) {
- CmdArgs.push_back("-lstdc++");
+ getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
@@ -2941,7 +2944,7 @@
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
if (D.CCCIsCXX) {
- CmdArgs.push_back("-lstdc++");
+ getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
// FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
@@ -3090,7 +3093,7 @@
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
if (D.CCCIsCXX) {
- CmdArgs.push_back("-lstdc++");
+ getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
@@ -3239,7 +3242,7 @@
}
if (D.CCCIsCXX) {
- CmdArgs.push_back("-lstdc++");
+ getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}