[llvm] r245670 - LTO: Simplify ownership of LTOCodeGenerator::CodegenOptions.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 21:45:55 PDT 2015


Author: pcc
Date: Thu Aug 20 23:45:55 2015
New Revision: 245670

URL: http://llvm.org/viewvc/llvm-project?rev=245670&view=rev
Log:
LTO: Simplify ownership of LTOCodeGenerator::CodegenOptions.

Modified:
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=245670&r1=245669&r2=245670&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Thu Aug 20 23:45:55 2015
@@ -165,7 +165,7 @@ private:
   lto_codegen_model CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
   StringSet MustPreserveSymbols;
   StringSet AsmUndefinedRefs;
-  std::vector<char *> CodegenOptions;
+  std::vector<std::string> CodegenOptions;
   std::string MCpu;
   std::string MAttr;
   std::string NativeObjectPath;

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=245670&r1=245669&r2=245670&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Thu Aug 20 23:45:55 2015
@@ -89,11 +89,6 @@ LTOCodeGenerator::~LTOCodeGenerator() {
 
   delete TargetMach;
   TargetMach = nullptr;
-
-  for (std::vector<char *>::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(
 /// LTO problems.
 void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) {
   for (std::pair<StringRef, StringRef> 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<char **>(&CodegenOptions[0]));
+  if (!CodegenOptions.empty()) {
+    // ParseCommandLineOptions() expects argv[0] to be program name.
+    std::vector<const char *> 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,




More information about the llvm-commits mailing list