From 54d8d8479c95d10aa479a1b30448d129528be325 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 13 Jan 2017 17:34:15 +0000 Subject: [PATCH] unique_ptrify createDriverOptTable git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291919 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 2 +- include/clang/Driver/Options.h | 4 +++- lib/Driver/Driver.cpp | 16 +++++++--------- lib/Driver/DriverOptions.cpp | 4 ++-- lib/Frontend/CompilerInvocation.cpp | 2 +- lib/FrontendTool/ExecuteCompilerInvocation.cpp | 2 +- lib/Tooling/Tooling.cpp | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 0ce461ca61..a5e0d5387d 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -62,7 +62,7 @@ enum LTOKind { /// Driver - Encapsulate logic for constructing compilation processes /// from a set of gcc-driver-like command line arguments. class Driver { - llvm::opt::OptTable *Opts; + std::unique_ptr Opts; DiagnosticsEngine &Diags; diff --git a/include/clang/Driver/Options.h b/include/clang/Driver/Options.h index 2716fa9ae8..e9d9000918 100644 --- a/include/clang/Driver/Options.h +++ b/include/clang/Driver/Options.h @@ -10,6 +10,8 @@ #ifndef LLVM_CLANG_DRIVER_OPTIONS_H #define LLVM_CLANG_DRIVER_OPTIONS_H +#include + namespace llvm { namespace opt { class OptTable; @@ -44,7 +46,7 @@ enum ID { }; } -llvm::opt::OptTable *createDriverOptTable(); +std::unique_ptr createDriverOptTable(); } } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 15f830d029..729209cf50 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -86,8 +86,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, } Driver::~Driver() { - delete Opts; - llvm::DeleteContainerSeconds(ToolChains); } @@ -214,9 +212,9 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL, return FinalPhase; } -static Arg *MakeInputArg(DerivedArgList &Args, OptTable *Opts, +static Arg *MakeInputArg(DerivedArgList &Args, OptTable &Opts, StringRef Value) { - Arg *A = new Arg(Opts->getOption(options::OPT_INPUT), Value, + Arg *A = new Arg(Opts.getOption(options::OPT_INPUT), Value, Args.getBaseArgs().MakeIndex(Value), Value.data()); Args.AddSynthesizedArg(A); A->claim(); @@ -287,7 +285,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { if (A->getOption().matches(options::OPT__DASH_DASH)) { A->claim(); for (StringRef Val : A->getValues()) - DAL->append(MakeInputArg(*DAL, Opts, Val)); + DAL->append(MakeInputArg(*DAL, *Opts, Val)); continue; } @@ -1561,14 +1559,14 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, } else if (A->getOption().matches(options::OPT__SLASH_Tc)) { StringRef Value = A->getValue(); if (DiagnoseInputExistence(*this, Args, Value, types::TY_C)) { - Arg *InputArg = MakeInputArg(Args, Opts, A->getValue()); + Arg *InputArg = MakeInputArg(Args, *Opts, A->getValue()); Inputs.push_back(std::make_pair(types::TY_C, InputArg)); } A->claim(); } else if (A->getOption().matches(options::OPT__SLASH_Tp)) { StringRef Value = A->getValue(); if (DiagnoseInputExistence(*this, Args, Value, types::TY_CXX)) { - Arg *InputArg = MakeInputArg(Args, Opts, A->getValue()); + Arg *InputArg = MakeInputArg(Args, *Opts, A->getValue()); Inputs.push_back(std::make_pair(types::TY_CXX, InputArg)); } A->claim(); @@ -1594,7 +1592,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, if (CCCIsCPP() && Inputs.empty()) { // If called as standalone preprocessor, stdin is processed // if no other input is present. - Arg *A = MakeInputArg(Args, Opts, "-"); + Arg *A = MakeInputArg(Args, *Opts, "-"); Inputs.push_back(std::make_pair(types::TY_C, A)); } } @@ -2497,7 +2495,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, const types::ID HeaderType = lookupHeaderTypeForSourceType(InputType); llvm::SmallVector PCHPL; types::getCompilationPhases(HeaderType, PCHPL); - Arg *PchInputArg = MakeInputArg(Args, Opts, YcArg->getValue()); + Arg *PchInputArg = MakeInputArg(Args, *Opts, YcArg->getValue()); // Build the pipeline for the pch file. Action *ClangClPch = diff --git a/lib/Driver/DriverOptions.cpp b/lib/Driver/DriverOptions.cpp index 8d5332b5cc..6a7410901d 100644 --- a/lib/Driver/DriverOptions.cpp +++ b/lib/Driver/DriverOptions.cpp @@ -39,6 +39,6 @@ public: } -OptTable *clang::driver::createDriverOptTable() { - return new DriverOptTable(); +std::unique_ptr clang::driver::createDriverOptTable() { + return llvm::make_unique(); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 36f6b0a511..2db6e0c495 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2405,7 +2405,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, bool Success = true; // Parse the arguments. - std::unique_ptr Opts(createDriverOptTable()); + std::unique_ptr Opts = createDriverOptTable(); const unsigned IncludedFlagsBitmask = options::CC1Option; unsigned MissingArgIndex, MissingArgCount; InputArgList Args = diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 187a6e7624..1f7493c9e3 100644 --- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -174,7 +174,7 @@ CreateFrontendAction(CompilerInstance &CI) { bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) { // Honor -help. if (Clang->getFrontendOpts().ShowHelp) { - std::unique_ptr Opts(driver::createDriverOptTable()); + std::unique_ptr Opts = driver::createDriverOptTable(); Opts->PrintHelp(llvm::outs(), "clang -cc1", "LLVM 'Clang' Compiler: http://clang.llvm.org", /*Include=*/ driver::options::CC1Option, /*Exclude=*/ 0); diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 25cee98078..9e1181281f 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -244,7 +244,7 @@ bool ToolInvocation::run() { const char *const BinaryName = Argv[0]; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); unsigned MissingArgIndex, MissingArgCount; - std::unique_ptr Opts(driver::createDriverOptTable()); + std::unique_ptr Opts = driver::createDriverOptTable(); llvm::opt::InputArgList ParsedArgs = Opts->ParseArgs( ArrayRef(Argv).slice(1), MissingArgIndex, MissingArgCount); ParseDiagnosticArgs(*DiagOpts, ParsedArgs); -- 2.40.0