From 3f1a1ffd95723068ad99992805bdc0734f2d72a8 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 14 Jun 2010 21:23:08 +0000 Subject: [PATCH] Driver: Eliminate uses of Arg::getIndex. Also, fix a memory leak. llvm-svn: 105963 --- clang/include/clang/Driver/ArgList.h | 6 ++++++ clang/lib/Driver/ToolChains.cpp | 7 ++++--- clang/lib/Driver/Tools.cpp | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Driver/ArgList.h b/clang/include/clang/Driver/ArgList.h index beec27cf053f..16396daa60ef 100644 --- a/clang/include/clang/Driver/ArgList.h +++ b/clang/include/clang/Driver/ArgList.h @@ -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 diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 19b1ec823db1..9accfe75167a 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -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 diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index d2c1f2d921cb..f61c02640ce7 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -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. -- GitLab