[cfe-commits] r67680 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td lib/Driver/ToolChains.cpp test/Driver/Xarch.c

Daniel Dunbar daniel at zuster.org
Tue Mar 24 23:12:35 PDT 2009


Author: ddunbar
Date: Wed Mar 25 01:12:34 2009
New Revision: 67680

URL: http://llvm.org/viewvc/llvm-project?rev=67680&view=rev
Log:
Driver: Handle -Xarch_, including warning for nasty -Xarch_ use cases
we aren't going to support. For example:
  clang -Xarch_i386 -S -Xarch_i386 -o -Xarch_i386 myi386asm.s ...

Added:
    cfe/trunk/test/Driver/Xarch.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/lib/Driver/ToolChains.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=67680&r1=67679&r2=67680&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Mar 25 01:12:34 2009
@@ -33,6 +33,8 @@
   "invalid Darwin version number: %0">;
 def err_drv_missing_argument : Error<
   "argument to '%0' is missing (expected %1 %plural{1:value|:values}1)">;
+def err_drv_invalid_Xarch_argument : Error<
+  "invalid Xarch argument: '%0'">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input file unused when '%2' is present">;

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=67680&r1=67679&r2=67680&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Mar 25 01:12:34 2009
@@ -12,7 +12,9 @@
 #include "clang/Driver/Arg.h"
 #include "clang/Driver/ArgList.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/HostInfo.h"
+#include "clang/Driver/Option.h"
 
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/System/Path.h"
@@ -125,8 +127,45 @@
 }
 
 DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const { 
-  // FIXME: Implement!
-  return new DerivedArgList(Args, true);
+  DerivedArgList *DAL = new DerivedArgList(Args, false);
+  
+  for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
+    Arg *A = *it;
+
+    if (A->getOption().matches(options::OPT_Xarch__)) {
+      // FIXME: Canonicalize name.
+      if (getArchName() != A->getValue(Args, 0))
+        continue;
+
+      // FIXME: The arg is leaked here, and we should have a nicer
+      // interface for this.
+      const Driver &D = getHost().getDriver();
+      unsigned Prev, Index = Prev = A->getIndex() + 1;
+      Arg *XarchArg = D.getOpts().ParseOneArg(Args, Index);
+      
+      // If the argument parsing failed or more than one argument was
+      // consumed, the -Xarch_ argument's parameter tried to consume
+      // extra arguments. Emit an error and ignore.
+      //
+      // We also want to disallow any options which would alter the
+      // driver behavior; that isn't going to work in our model. We
+      // use isDriverOption() as an approximation, although things
+      // like -O4 are going to slip through.
+      if (!XarchArg || Index > Prev + 1 || 
+          XarchArg->getOption().isDriverOption()) {
+        D.Diag(clang::diag::err_drv_invalid_Xarch_argument)
+          << A->getAsString(Args);
+        continue;
+      }
+
+      A = XarchArg;
+    } 
+
+    // FIXME: Translate.
+    DAL->append(A);
+  }
+
+  return DAL;
 } 
 
 bool Darwin_X86::IsMathErrnoDefault() const { 

Added: cfe/trunk/test/Driver/Xarch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Xarch.c?rev=67680&view=auto

==============================================================================
--- cfe/trunk/test/Driver/Xarch.c (added)
+++ cfe/trunk/test/Driver/Xarch.c Wed Mar 25 01:12:34 2009
@@ -0,0 +1,10 @@
+// RUN: clang -ccc-host-triple i386-apple-darwin9 -m32 -Xarch_i386 -O2 %s -S -### 2> %t.log &&
+// RUN: grep ' "-O2" ' %t.log | count 1 &&
+// RUN: clang -ccc-host-triple i386-apple-darwin9 -m64 -Xarch_i386 -O2 %s -S -### 2> %t.log &&
+// RUN: grep ' "-O2" ' %t.log | count 0 &&
+// RUN: grep "argument unused during compilation: '-Xarch_i386 -O2'" %t.log &&
+// RUN: not clang -ccc-host-triple i386-apple-darwin9 -m32 -Xarch_i386 -o -Xarch_i386 -S %s -S -Xarch_i386 -o 2> %t.log &&
+// RUN: grep "error: invalid Xarch argument: '-Xarch_i386 -o'" %t.log | count 2 &&
+// RUN: grep "error: invalid Xarch argument: '-Xarch_i386 -S'" %t.log &&
+// RUN: true
+





More information about the cfe-commits mailing list