1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

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

Fixes an issue with missing nul-terminators and saves us some string
copying, compared to a version which would insert nul-terminators.

Differential Revision: https://reviews.llvm.org/D82033
This commit is contained in:
Momchil Velikov 2020-06-22 11:14:53 +01:00
parent b2e4c430fd
commit a064519335
3 changed files with 9 additions and 6 deletions

View File

@ -123,7 +123,7 @@ struct LTOCodeGenerator {
/// 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.
///

View File

@ -632,9 +632,9 @@ bool LTOCodeGenerator::compileOptimized(ArrayRef<raw_pwrite_stream *> Out) {
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() {

View File

@ -474,17 +474,20 @@ bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
}
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; }