Driver: Eliminate uses of Arg::getIndex.

Also, fix a memory leak.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105963 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 19b1ec8..9accfe7 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -487,9 +487,8 @@
       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 @@
 
       XarchArg->setBaseArg(A);
       A = XarchArg;
+
+      DAL->AddSynthesizedArg(A);
     }
 
     // Sob. These is strictly gcc compatible for the time being. Apple
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index d2c1f2d..f61c026 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1074,8 +1074,9 @@
     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.