[cfe-commits] r81420 - /cfe/trunk/lib/Driver/Tools.cpp

Daniel Dunbar daniel at zuster.org
Wed Sep 9 18:21:05 PDT 2009


Author: ddunbar
Date: Wed Sep  9 20:21:05 2009
New Revision: 81420

URL: http://llvm.org/viewvc/llvm-project?rev=81420&view=rev
Log:
Factor out CheckPreprocessing options to share between Clang/CC1 tools.

Also, fix forwarding of -C/-CC to cc1.

Modified:
    cfe/trunk/lib/Driver/Tools.cpp

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep  9 20:21:05 2009
@@ -39,6 +39,15 @@
   return Args.MakeArgString(Str.str());
 }
 
+/// CheckPreprocessingOptions - Perform some validation of preprocessing
+/// arguments that is shared with gcc.
+static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) {
+  if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC))
+    if (!Args.hasArg(options::OPT_E))
+      D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+        << A->getAsString(Args) << "-E";
+}
+
 void Clang::AddPreprocessingOptions(const Driver &D,
                                     const ArgList &Args,
                                     ArgStringList &CmdArgs,
@@ -46,13 +55,10 @@
                                     const InputInfoList &Inputs) const {
   Arg *A;
 
-  if ((A = Args.getLastArg(options::OPT_C)) ||
-      (A = Args.getLastArg(options::OPT_CC))) {
-    if (!Args.hasArg(options::OPT_E))
-      D.Diag(clang::diag::err_drv_argument_only_allowed_with)
-        << A->getAsString(Args) << "-E";
-    A->render(Args, CmdArgs);
-  }
+  CheckPreprocessingOptions(D, Args);
+
+  Args.AddLastArg(CmdArgs, options::OPT_C);
+  Args.AddLastArg(CmdArgs, options::OPT_CC);
 
   // Handle dependency file generation.
   if ((A = Args.getLastArg(options::OPT_M)) ||
@@ -1042,14 +1048,12 @@
                                           const InputInfoList &Inputs) const {
   const Driver &D = getToolChain().getHost().getDriver();
 
+  CheckPreprocessingOptions(D, Args);
+
   // Derived from cpp_unique_options.
-  Arg *A;
-  if ((A = Args.getLastArg(options::OPT_C)) ||
-      (A = Args.getLastArg(options::OPT_CC))) {
-    if (!Args.hasArg(options::OPT_E))
-      D.Diag(clang::diag::err_drv_argument_only_allowed_with)
-        << A->getAsString(Args) << "-E";
-  }
+  // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
+  Args.AddLastArg(CmdArgs, options::OPT_C);
+  Args.AddLastArg(CmdArgs, options::OPT_CC);
   if (!Args.hasArg(options::OPT_Q))
     CmdArgs.push_back("-quiet");
   Args.AddAllArgs(CmdArgs, options::OPT_nostdinc);





More information about the cfe-commits mailing list