[cfe-commits] r133547 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/HeaderSearchOptions.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitHeaderSearch.cpp

Bob Wilson bob.wilson at apple.com
Tue Jun 21 14:12:29 PDT 2011


Author: bwilson
Date: Tue Jun 21 16:12:29 2011
New Revision: 133547

URL: http://llvm.org/viewvc/llvm-project?rev=133547&view=rev
Log:
Fix the default libc++ header search path to be sysrooted.  Radar 9639692.

The -cxx-isystem path is not prefixed with the sysroot directory, so it's
not a good way for the driver to set the system default C++ search path.
Instead, add -stdlib as a cc1 option and teach the frontend how to find the
headers.  The driver can then just pass -stdlib through to "cc1".

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
    cfe/trunk/lib/Driver/ToolChain.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Jun 21 16:12:29 2011
@@ -461,6 +461,8 @@
   HelpText<"Generate weak vtables and RTTI with hidden visibility">;
 def std_EQ : Joined<"-std=">,
   HelpText<"Language standard to compile for">;
+def stdlib_EQ : Joined<"-stdlib=">,
+  HelpText<"C++ standard library to use">;
 def fmath_errno : Flag<"-fmath-errno">,
   HelpText<"Require math functions to indicate errors by setting errno">;
 def fms_extensions : Flag<"-fms-extensions">,

Modified: cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h Tue Jun 21 16:12:29 2011
@@ -82,13 +82,16 @@
   /// Include the system standard C++ library include search directories.
   unsigned UseStandardCXXIncludes : 1;
 
+  /// Use libc++ instead of the default libstdc++.
+  unsigned UseLibcxx : 1;
+
   /// Whether header search information should be output as for -v.
   unsigned Verbose : 1;
 
 public:
   HeaderSearchOptions(llvm::StringRef _Sysroot = "/")
     : Sysroot(_Sysroot), UseBuiltinIncludes(true),
-      UseStandardIncludes(true), UseStandardCXXIncludes(true),
+      UseStandardIncludes(true), UseStandardCXXIncludes(true), UseLibcxx(false),
       Verbose(false) {}
 
   /// AddPath - Add the \arg Path path to the specified \arg Group list.

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Tue Jun 21 16:12:29 2011
@@ -205,19 +205,15 @@
                                              bool ObjCXXAutoRefCount) const {
   CXXStdlibType Type = GetCXXStdlibType(Args);
 
+  // Header search paths are handled by the mass of goop in InitHeaderSearch.
+
   switch (Type) {
   case ToolChain::CST_Libcxx:
-    CmdArgs.push_back("-nostdinc++");
-    CmdArgs.push_back("-cxx-isystem");
-    CmdArgs.push_back("/usr/include/c++/v1");
-      
     if (ObjCXXAutoRefCount)
       CmdArgs.push_back("-fobjc-arc-cxxlib=libc++");
     break;
 
   case ToolChain::CST_Libstdcxx:
-    // Currently handled by the mass of goop in InitHeaderSearch.
-
     if (ObjCXXAutoRefCount)
       CmdArgs.push_back("-fobjc-arc-cxxlib=libstdc++");
     break;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Jun 21 16:12:29 2011
@@ -330,6 +330,7 @@
       = types::isObjC(InputType) && isObjCAutoRefCount(Args);
     getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs, 
                                                 ObjCXXAutoRefCount);
+    Args.AddAllArgs(CmdArgs, options::OPT_stdlib_EQ);
   }
 
   // Add -Wp, and -Xassembler if using the preprocessor.

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jun 21 16:12:29 2011
@@ -553,6 +553,8 @@
     Res.push_back("-nostdinc");
   if (!Opts.UseStandardCXXIncludes)
     Res.push_back("-nostdinc++");
+  if (Opts.UseLibcxx)
+    Res.push_back("-stdlib=libc++");
   if (Opts.Verbose)
     Res.push_back("-v");
 }
@@ -1330,6 +1332,8 @@
   Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
   Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
   Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx);
+  if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
+    Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0);
   Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir);
 
   // Add -I... and -F... options in order.

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=133547&r1=133546&r2=133547&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Tue Jun 21 16:12:29 2011
@@ -920,8 +920,12 @@
 void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
                                                     const llvm::Triple &triple,
                                             const HeaderSearchOptions &HSOpts) {
-  if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes)
-    AddDefaultCPlusPlusIncludePaths(triple);
+  if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) {
+    if (HSOpts.UseLibcxx)
+      AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
+    else
+      AddDefaultCPlusPlusIncludePaths(triple);
+  }
 
   AddDefaultCIncludePaths(triple, HSOpts);
 





More information about the cfe-commits mailing list