[cfe-commits] r113891 - in /cfe/trunk: docs/tools/clang.pod include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Options.td include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp
Daniel Dunbar
daniel at zuster.org
Tue Sep 14 16:12:40 PDT 2010
Author: ddunbar
Date: Tue Sep 14 18:12:40 2010
New Revision: 113891
URL: http://llvm.org/viewvc/llvm-project?rev=113891&view=rev
Log:
Driver: Add a -stdlib= argument which can be used to select the C++ standard
library to use.
- This is currently useful for testing libc++; you can now use 'clang++
-stdlib=libc++ t.cpp' to compile using it if installed.
- In the future could also be used to select other standard library choices if
alternatives become available (for example, to use an alternate C library).
Modified:
cfe/trunk/docs/tools/clang.pod
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
Modified: cfe/trunk/docs/tools/clang.pod
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/clang.pod?rev=113891&r1=113890&r2=113891&view=diff
==============================================================================
--- cfe/trunk/docs/tools/clang.pod (original)
+++ cfe/trunk/docs/tools/clang.pod Tue Sep 14 18:12:40 2010
@@ -14,6 +14,7 @@
B<-f>I<feature-option...>
B<-m>I<machine-option...>
B<-o> I<output-file>
+ B<-stdlib=>I<library>
I<input-filenames>
=head1 DESCRIPTION
@@ -130,6 +131,11 @@
Specify the language standard to compile for.
+=item B<-stdlib>=I<language>
+
+Specify the C++ standard library to use; supported options are libstdc++ and
+libc++.
+
=item B<-ansi>
Same as B<-std=c89>.
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=113891&r1=113890&r2=113891&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Tue Sep 14 18:12:40 2010
@@ -16,6 +16,8 @@
def err_drv_unknown_language : Error<"language not recognized: '%0'">;
def err_drv_invalid_arch_name : Error<
"invalid arch name '%0'">;
+def err_drv_invalid_stdlib_name : Error<
+ "invalid library name in argument '%0'">;
def err_drv_invalid_opt_with_multiple_archs : Error<
"option '%0' cannot be used with multiple -arch options">;
def err_drv_invalid_output_with_multiple_archs : Error<
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=113891&r1=113890&r2=113891&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Sep 14 18:12:40 2010
@@ -575,6 +575,7 @@
def static : Flag<"-static">, Flags<[NoArgumentUnused]>;
def std_default_EQ : Joined<"-std-default=">;
def std_EQ : Joined<"-std=">;
+def stdlib_EQ : Joined<"-stdlib=">;
def sub__library : JoinedOrSeparate<"-sub_library">;
def sub__umbrella : JoinedOrSeparate<"-sub_umbrella">;
def s : Flag<"-s">;
@@ -719,6 +720,8 @@
def _static : Flag<"--static">, Alias<static>;
def _std_EQ : Joined<"--std=">, Alias<std_EQ>;
def _std : Separate<"--std">, Alias<std_EQ>;
+def _stdlib_EQ : Joined<"--stdlib=">, Alias<std_EQ>;
+def _stdlib : Separate<"--stdlib">, Alias<std_EQ>;
def _sysroot_EQ : Joined<"--sysroot=">;
def _sysroot : Separate<"--sysroot">, Alias<_sysroot_EQ>;
def _target_help : Flag<"--target-help">;
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=113891&r1=113890&r2=113891&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Sep 14 18:12:40 2010
@@ -34,6 +34,7 @@
typedef llvm::SmallVector<std::string, 4> path_list;
enum CXXStdlibType {
+ CST_Libcxx,
CST_Libstdcxx
};
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=113891&r1=113890&r2=113891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Tue Sep 14 18:12:40 2010
@@ -175,6 +175,16 @@
}
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
+ if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
+ llvm::StringRef Value = A->getValue(Args);
+ if (Value == "libc++")
+ return ToolChain::CST_Libcxx;
+ if (Value == "libstdc++")
+ return ToolChain::CST_Libstdcxx;
+ getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
+ << A->getAsString(Args);
+ }
+
return ToolChain::CST_Libstdcxx;
}
@@ -183,6 +193,11 @@
CXXStdlibType Type = GetCXXStdlibType(Args);
switch (Type) {
+ case ToolChain::CST_Libcxx:
+ CmdArgs.push_back("-cxx-system-include");
+ CmdArgs.push_back("/usr/include/c++/v1");
+ break;
+
case ToolChain::CST_Libstdcxx:
// Currently handled by the mass of goop in InitHeaderSearch.
break;
@@ -194,6 +209,10 @@
CXXStdlibType Type = GetCXXStdlibType(Args);
switch (Type) {
+ case ToolChain::CST_Libcxx:
+ CmdArgs.push_back("-lc++");
+ break;
+
case ToolChain::CST_Libstdcxx:
CmdArgs.push_back("-lstdc++");
break;
More information about the cfe-commits
mailing list