[cfe-commits] r91237 - in /cfe/trunk: include/clang/Frontend/CompilerInvocation.h include/clang/Frontend/HeaderSearchOptions.h lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitHeaderSearch.cpp tools/driver/cc1_main.cpp

Daniel Dunbar daniel at zuster.org
Sat Dec 12 19:45:58 PST 2009


Author: ddunbar
Date: Sat Dec 12 21:45:58 2009
New Revision: 91237

URL: http://llvm.org/viewvc/llvm-project?rev=91237&view=rev
Log:
CompilerInvocation: Move builtin-include-path logic out of CompilerInvocation::CreateFromArgs.

Modified:
    cfe/trunk/include/clang/Frontend/CompilerInvocation.h
    cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
    cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Sat Dec 12 21:45:58 2009
@@ -82,15 +82,19 @@
   /// \param Res [out] - The resulting invocation.
   /// \param ArgBegin - The first element in the argument vector.
   /// \param ArgEnd - The last element in the argument vector.
+  /// \param Diags - The diagnostic engine to use for errors.
+  static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
+                             const char **ArgEnd, Diagnostic &Diags);
+
+  /// GetBuiltinIncludePath - Get the directory where the compiler headers
+  /// reside, relative to the compiler binary (found by the passed in
+  /// arguments).
+  ///
   /// \param Argv0 - The program path (from argv[0]), for finding the builtin
   /// compiler path.
   /// \param MainAddr - The address of main (or some other function in the main
   /// executable), for finding the builtin compiler path.
-  /// \param Diags - The diagnostic engine to use for errors.
-  static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
-                             const char **ArgEnd, const char *Argv0,
-                             void *MainAddr,
-                             Diagnostic &Diags);
+  static std::string GetBuiltinIncludePath(const char *Argv0, void *MainAddr);
 
   /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
   /// passing to CreateFromArgs.

Modified: cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h Sat Dec 12 21:45:58 2009
@@ -65,6 +65,9 @@
   /// will be searched following the user and environment includes.
   std::string BuiltinIncludePath;
 
+  /// Include the compiler builtin includes.
+  unsigned UseBuiltinIncludes : 1;
+
   /// Include the system standard include search directories.
   unsigned UseStandardIncludes : 1;
 
@@ -73,7 +76,8 @@
 
 public:
   HeaderSearchOptions(llvm::StringRef _Sysroot = "/")
-    : Sysroot(_Sysroot), UseStandardIncludes(true), Verbose(false) {}
+    : Sysroot(_Sysroot), UseBuiltinIncludes(true),
+      UseStandardIncludes(true), Verbose(false) {}
 
   /// AddPath - Add the \arg Path path to the specified \arg Group list.
   void AddPath(llvm::StringRef Path, frontend::IncludeDirGroup Group,

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sat Dec 12 21:45:58 2009
@@ -327,7 +327,13 @@
   CompilerInvocation CI;
   CompilerInvocation::CreateFromArgs(CI, (const char**) CCArgs.data(),
                                      (const char**) CCArgs.data()+CCArgs.size(),
-                                     Argv0, MainAddr, Diags);
+                                     Diags);
+
+  // Infer the builtin include path if unspecified.
+  if (CI.getHeaderSearchOpts().UseBuiltinIncludes &&
+      CI.getHeaderSearchOpts().BuiltinIncludePath.empty())
+    CI.getHeaderSearchOpts().BuiltinIncludePath =
+      CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr);
 
   CI.getFrontendOpts().DisableFree = UseBumpAllocator;
   return LoadFromCompilerInvocation(CI, Diags, OnlyLocalDecls);

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Dec 12 21:45:58 2009
@@ -951,8 +951,8 @@
   return DashX;
 }
 
-static std::string GetBuiltinIncludePath(const char *Argv0,
-                                         void *MainAddr) {
+std::string CompilerInvocation::GetBuiltinIncludePath(const char *Argv0,
+                                                      void *MainAddr) {
   llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr);
 
   if (!P.isEmpty()) {
@@ -969,16 +969,16 @@
   return P.str();
 }
 
-static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
-                                  const char *Argv0, void *MainAddr) {
+static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
   using namespace cc1options;
   Opts.Sysroot = getLastArgValue(Args, OPT_isysroot, "/");
   Opts.Verbose = Args.hasArg(OPT_v);
+  Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
   Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
+  // Filled in by clients.
+  //
+  // FIXME: Elimate this.
   Opts.BuiltinIncludePath = "";
-  // FIXME: Add an option for this, its a slow call.
-  if (!Args.hasArg(OPT_nobuiltininc))
-    Opts.BuiltinIncludePath = GetBuiltinIncludePath(Argv0, MainAddr);
 
   // Add -I... and -F... options in order.
   for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F),
@@ -1262,8 +1262,6 @@
 void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
                                         const char **ArgBegin,
                                         const char **ArgEnd,
-                                        const char *Argv0,
-                                        void *MainAddr,
                                         Diagnostic &Diags) {
   // Parse the arguments.
   llvm::OwningPtr<OptTable> Opts(createCC1OptTable());
@@ -1287,8 +1285,7 @@
   ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags);
   FrontendOptions::InputKind DashX =
     ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
-  ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args,
-                        Argv0, MainAddr);
+  ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
   if (DashX != FrontendOptions::IK_AST)
     ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
   ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, Diags);

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Sat Dec 12 21:45:58 2009
@@ -730,7 +730,7 @@
   else
     Init.AddDelimitedPaths(HSOpts.CEnvIncPath);
 
-  if (!HSOpts.BuiltinIncludePath.empty()) {
+  if (HSOpts.UseBuiltinIncludes) {
     // Ignore the sys root, we *always* look for clang headers relative to
     // supplied path.
     Init.AddPath(HSOpts.BuiltinIncludePath, System,

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=91237&r1=91236&r2=91237&view=diff

==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Sat Dec 12 21:45:58 2009
@@ -121,8 +121,7 @@
 
 // FIXME: Define the need for this testing away.
 static int cc1_test(Diagnostic &Diags,
-                    const char **ArgBegin, const char **ArgEnd,
-                    const char *Argv0, void *MainAddr) {
+                    const char **ArgBegin, const char **ArgEnd) {
   using namespace clang::driver;
 
   llvm::errs() << "cc1 argv:";
@@ -150,8 +149,7 @@
   // Create a compiler invocation.
   llvm::errs() << "cc1 creating invocation.\n";
   CompilerInvocation Invocation;
-  CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
-                                     Argv0, MainAddr, Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd, Diags);
 
   // Convert the invocation back to argument strings.
   std::vector<std::string> InvocationArgs;
@@ -170,8 +168,7 @@
   // same thing.
   CompilerInvocation Invocation2;
   CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
-                                     Invocation2Args.end(), Argv0, MainAddr,
-                                     Diags);
+                                     Invocation2Args.end(), Diags);
 
   // FIXME: Implement CompilerInvocation comparison.
   if (true) {
@@ -198,7 +195,7 @@
   if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
     TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
     Diagnostic Diags(&DiagClient);
-    return cc1_test(Diags, ArgBegin + 1, ArgEnd, Argv0, MainAddr);
+    return cc1_test(Diags, ArgBegin + 1, ArgEnd);
   }
 
   // Initialize targets first, so that --version shows registered targets.
@@ -210,7 +207,13 @@
   TextDiagnosticBuffer DiagsBuffer;
   Diagnostic Diags(&DiagsBuffer);
   CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
-                                     Argv0, MainAddr, Diags);
+                                     Diags);
+
+  // Infer the builtin include path if unspecified.
+  if (Clang.getInvocation().getHeaderSearchOpts().UseBuiltinIncludes &&
+      Clang.getInvocation().getHeaderSearchOpts().BuiltinIncludePath.empty())
+    Clang.getInvocation().getHeaderSearchOpts().BuiltinIncludePath =
+      CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr);
 
   // Honor -help.
   if (Clang.getInvocation().getFrontendOpts().ShowHelp) {
@@ -232,7 +235,7 @@
   Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
   if (!Clang.hasDiagnostics())
     return 1;
-  
+
   // Set an error handler, so that any LLVM backend diagnostics go through our
   // error handler.
   llvm::llvm_install_error_handler(LLVMErrorHandler,





More information about the cfe-commits mailing list