]> granicus.if.org Git - clang/commitdiff
Driver: Eliminate uses of Arg::getIndex.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 14 Jun 2010 21:23:08 +0000 (21:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 14 Jun 2010 21:23:08 +0000 (21:23 +0000)
Also, fix a memory leak.

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

include/clang/Driver/ArgList.h
lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp

index beec27cf053fd362b73e6c369b321fd66861ca27..16396daa60ef9fb2a1c9c2a77db6745a72483923 100644 (file)
@@ -338,6 +338,12 @@ namespace driver {
     /// @name Arg Synthesis
     /// @{
 
+    /// AddSynthesizedArg - Add a argument to the list of synthesized arguments
+    /// (to be freed).
+    void AddSynthesizedArg(Arg *A) {
+      SynthesizedArgs.push_back(A);
+    }
+
     virtual const char *MakeArgString(llvm::StringRef Str) const;
 
     /// AddFlagArg - Construct a new FlagArg for the given option \arg Id and
index 19b1ec823db1fc9ccd892a0f7a77daab53f064c3..9accfe75167a9914282fa2ad17e9f8265ababfe3 100644 (file)
@@ -487,9 +487,8 @@ DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
       if (getArchName() != A->getValue(Args, 0))
         continue;
 
-      // FIXME: The arg is leaked here, and we should have a nicer
-      // interface for this.
-      unsigned Prev, Index = Prev = A->getIndex() + 1;
+      unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
+      unsigned Prev = Index;
       Arg *XarchArg = Opts.ParseOneArg(Args, Index);
 
       // If the argument parsing failed or more than one argument was
@@ -509,6 +508,8 @@ DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
 
       XarchArg->setBaseArg(A);
       A = XarchArg;
+
+      DAL->AddSynthesizedArg(A);
     }
 
     // Sob. These is strictly gcc compatible for the time being. Apple
index d2c1f2d921cb75c5ea82ad95821498a2d7e85dbb..f61c02640ce7e0b4066d152507d280e2321f1c9a 100644 (file)
@@ -1074,8 +1074,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     else
       Std->render(Args, CmdArgs);
 
-    if (Arg *A = Args.getLastArg(options::OPT_trigraphs))
-      if (A->getIndex() > Std->getIndex())
+    if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
+                                 options::OPT_trigraphs))
+      if (A != Std)
         A->render(Args, CmdArgs);
   } else {
     // Honor -std-default.