[cfe-commits] r157205 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp lib/Driver/ToolChains.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CreateInvocationFromCommandLine.cpp test/Index/index-kernel-invocation.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon May 21 13:11:54 PDT 2012


Author: akirtzidis
Date: Mon May 21 15:11:54 2012
New Revision: 157205

URL: http://llvm.org/viewvc/llvm-project?rev=157205&view=rev
Log:
[driver] When creating the compiler invocation out of command-line
arguments, force use of clang frontend for the driver.

Fixes rdar://11356765.

Added:
    cfe/trunk/test/Index/index-kernel-invocation.cpp
Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/CreateInvocationFromCommandLine.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=157205&r1=157204&r2=157205&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Mon May 21 15:11:54 2012
@@ -156,6 +156,9 @@
   /// used where an integrated CPP would).
   unsigned CCCUseClangCPP : 1;
 
+  /// \brief Force use of clang frontend.
+  unsigned ForcedClangUse : 1;
+
 public:
   /// Use lazy precompiled headers for PCH support.
   unsigned CCCUsePCH : 1;
@@ -229,6 +232,9 @@
     InstalledDir = Value;
   }
 
+  bool shouldForceClangUse() const { return ForcedClangUse; }
+  void setForcedClangUse(bool V = true) { ForcedClangUse = V; }
+
   /// @}
   /// @name Primary Functionality
   /// @{

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=157205&r1=157204&r2=157205&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon May 21 15:11:54 2012
@@ -59,7 +59,7 @@
     CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
     CCGenDiagnostics(false), CCCGenericGCCName(""), CheckInputsExist(true),
     CCCUseClang(true), CCCUseClangCXX(true), CCCUseClangCPP(true),
-    CCCUsePCH(true), SuppressMissingInputWarning(false) {
+    ForcedClangUse(false), CCCUsePCH(true), SuppressMissingInputWarning(false) {
   if (IsProduction) {
     // In a "production" build, only use clang on architectures we expect to
     // work.

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=157205&r1=157204&r2=157205&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon May 21 15:11:54 2012
@@ -199,21 +199,25 @@
 
 Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA,
                          const ActionList &Inputs) const {
-  Action::ActionClass Key;
+  Action::ActionClass Key = JA.getKind();
+  bool useClang = false;
 
   if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) {
+    useClang = true;
     // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI.
-    if (Inputs.size() == 1 &&
+    if (!getDriver().shouldForceClangUse() &&
+        Inputs.size() == 1 &&
         types::isCXX(Inputs[0]->getType()) &&
         getTriple().isOSDarwin() &&
         getTriple().getArch() == llvm::Triple::x86 &&
         (C.getArgs().getLastArg(options::OPT_fapple_kext) ||
          C.getArgs().getLastArg(options::OPT_mkernel)))
-      Key = JA.getKind();
-    else
-      Key = Action::AnalyzeJobClass;
-  } else
-    Key = JA.getKind();
+      useClang = false;
+  }
+
+  // FIXME: This seems like a hacky way to choose clang frontend.
+  if (useClang)
+    Key = Action::AnalyzeJobClass;
 
   bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
                                              options::OPT_no_integrated_as,

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=157205&r1=157204&r2=157205&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon May 21 15:11:54 2012
@@ -17,12 +17,6 @@
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/TypeOrdering.h"
 #include "clang/AST/StmtVisitor.h"
-#include "clang/Driver/Compilation.h"
-#include "clang/Driver/Driver.h"
-#include "clang/Driver/Job.h"
-#include "clang/Driver/ArgList.h"
-#include "clang/Driver/Options.h"
-#include "clang/Driver/Tool.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"

Modified: cfe/trunk/lib/Frontend/CreateInvocationFromCommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CreateInvocationFromCommandLine.cpp?rev=157205&r1=157204&r2=157205&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CreateInvocationFromCommandLine.cpp (original)
+++ cfe/trunk/lib/Frontend/CreateInvocationFromCommandLine.cpp Mon May 21 15:11:54 2012
@@ -43,13 +43,17 @@
   Args.push_back("<clang>"); // FIXME: Remove dummy argument.
   Args.insert(Args.end(), ArgList.begin(), ArgList.end());
 
-  // FIXME: Find a cleaner way to force the driver into restricted modes. We
-  // also want to force it to use clang.
+  // FIXME: Find a cleaner way to force the driver into restricted modes.
   Args.push_back("-fsyntax-only");
 
   // FIXME: We shouldn't have to pass in the path info.
   driver::Driver TheDriver("clang", llvm::sys::getDefaultTargetTriple(),
                            "a.out", false, *Diags);
+  // Force driver to use clang.
+  // FIXME: This seems like a hack. Maybe the "Clang" tool subclass should be
+  // available for using it to get the arguments, thus avoiding the overkill
+  // of using the driver.
+  TheDriver.setForcedClangUse();
 
   // Don't check that inputs exist, they may have been remapped.
   TheDriver.setCheckInputsExist(false);

Added: cfe/trunk/test/Index/index-kernel-invocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-kernel-invocation.cpp?rev=157205&view=auto
==============================================================================
--- cfe/trunk/test/Index/index-kernel-invocation.cpp (added)
+++ cfe/trunk/test/Index/index-kernel-invocation.cpp Mon May 21 15:11:54 2012
@@ -0,0 +1,4 @@
+// RUN: c-index-test -index-file -arch i386 -mkernel %s | FileCheck %s
+
+// CHECK: [indexDeclaration]: kind: function | name: foobar
+void foobar(void);





More information about the cfe-commits mailing list