]> granicus.if.org Git - clang/commitdiff
Driver: Handle -Xarch_, including warning for nasty -Xarch_ use cases
authorDaniel Dunbar <daniel@zuster.org>
Wed, 25 Mar 2009 06:12:34 +0000 (06:12 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 25 Mar 2009 06:12:34 +0000 (06:12 +0000)
we aren't going to support. For example:
  clang -Xarch_i386 -S -Xarch_i386 -o -Xarch_i386 myi386asm.s ...

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67680 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticDriverKinds.td
lib/Driver/ToolChains.cpp
test/Driver/Xarch.c [new file with mode: 0644]

index 3fb816ee63f300e2150e1368eae5b6baa5432a1b..b1b83b5c4bdbe44ac717aad407fe2b89a815d769 100644 (file)
@@ -33,6 +33,8 @@ def err_drv_invalid_darwin_version : Error<
   "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">;
index 898f12e8f2502a6afecf769d922bbc1d48b83225..866cfa15dce8811567ae1df8c0903f5c51c8300f 100644 (file)
@@ -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 @@ Tool &Darwin_X86::SelectTool(const Compilation &C,
 }
 
 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 { 
diff --git a/test/Driver/Xarch.c b/test/Driver/Xarch.c
new file mode 100644 (file)
index 0000000..a2a3fde
--- /dev/null
@@ -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
+