[PATCH] D82033: [LTO] Use StringRef instead of C-style strings in setCodeGenDebugOptions

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 03:44:25 PDT 2020


chill updated this revision to Diff 271992.
chill retitled this revision from "[LTO] Nul-terminate options passed to LLVM" to "[LTO] Use StringRef instead of C-style strings in setCodeGenDebugOptions".
chill edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82033/new/

https://reviews.llvm.org/D82033

Files:
  llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/tools/lto/lto.cpp


Index: llvm/tools/lto/lto.cpp
===================================================================
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -474,17 +474,20 @@
 }
 
 void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {
-  std::vector<const char *> Options;
+  SmallVector<StringRef, 4> Options;
   for (std::pair<StringRef, StringRef> o = getToken(opt); !o.first.empty();
        o = getToken(o.second))
-    Options.push_back(o.first.data());
+    Options.push_back(o.first);
 
   unwrap(cg)->setCodeGenDebugOptions(Options);
 }
 
 void lto_codegen_debug_options_array(lto_code_gen_t cg,
                                      const char *const *options, int number) {
-  unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(options, number));
+  SmallVector<StringRef, 4> Options;
+  for (int i = 0; i < number; ++i)
+    Options.push_back(options[i]);
+  unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(Options));
 }
 
 unsigned int lto_api_version() { return LTO_API_VERSION; }
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -632,9 +632,9 @@
   return true;
 }
 
-void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef<const char *> Options) {
+void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef<StringRef> Options) {
   for (StringRef Option : Options)
-    CodegenOptions.push_back(std::string(Option));
+    CodegenOptions.push_back(Option.str());
 }
 
 void LTOCodeGenerator::parseCodeGenDebugOptions() {
Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
===================================================================
--- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -123,7 +123,7 @@
   /// name is misleading).  This function should be called before
   /// LTOCodeGenerator::compilexxx(), and
   /// LTOCodeGenerator::writeMergedModules().
-  void setCodeGenDebugOptions(ArrayRef<const char *> Opts);
+  void setCodeGenDebugOptions(ArrayRef<StringRef> Opts);
 
   /// Parse the options set in setCodeGenDebugOptions.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82033.271992.patch
Type: text/x-patch
Size: 2170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200619/33da7d96/attachment.bin>


More information about the llvm-commits mailing list