From: Peter Collingbourne Date: Fri, 21 Aug 2015 04:45:55 +0000 (+0000) Subject: LTO: Simplify ownership of LTOCodeGenerator::CodegenOptions. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=ad3f32e4a59af726de857d05b81e69d3373ca38e LTO: Simplify ownership of LTOCodeGenerator::CodegenOptions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245670 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index 0c46fc048a4..695de5aa994 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -165,7 +165,7 @@ private: lto_codegen_model CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT; StringSet MustPreserveSymbols; StringSet AsmUndefinedRefs; - std::vector CodegenOptions; + std::vector CodegenOptions; std::string MCpu; std::string MAttr; std::string NativeObjectPath; diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index daaf2232922..fdf3f3a2b89 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -89,11 +89,6 @@ LTOCodeGenerator::~LTOCodeGenerator() { delete TargetMach; TargetMach = nullptr; - - for (std::vector::iterator I = CodegenOptions.begin(), - E = CodegenOptions.end(); - I != E; ++I) - free(*I); } // Initialize LTO passes. Please keep this funciton in sync with @@ -575,20 +570,19 @@ bool LTOCodeGenerator::compileOptimized(raw_pwrite_stream &out, /// LTO problems. void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { for (std::pair o = getToken(options); - !o.first.empty(); o = getToken(o.second)) { - // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add - // that. - if (CodegenOptions.empty()) - CodegenOptions.push_back(strdup("libLLVMLTO")); - CodegenOptions.push_back(strdup(o.first.str().c_str())); - } + !o.first.empty(); o = getToken(o.second)) + CodegenOptions.push_back(o.first); } void LTOCodeGenerator::parseCodeGenDebugOptions() { // if options were requested, set them - if (!CodegenOptions.empty()) - cl::ParseCommandLineOptions(CodegenOptions.size(), - const_cast(&CodegenOptions[0])); + if (!CodegenOptions.empty()) { + // ParseCommandLineOptions() expects argv[0] to be program name. + std::vector CodegenArgv(1, "libLLVMLTO"); + for (std::string &Arg : CodegenOptions) + CodegenArgv.push_back(Arg.c_str()); + cl::ParseCommandLineOptions(CodegenArgv.size(), CodegenArgv.data()); + } } void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI,