Skip to content

Commit e6d1856

Browse files
Rollup merge of rust-lang#138117 - cuviper:passwrapper-size_t, r=Urgau
[llvm/PassWrapper] use `size_t` when building arg strings While we're unlikely to ever overflow `int` in this case, it's still more proper to use `size_t` consistently when dealing with buffer lengths. If nothing else, this fixes a few `-Wsign-compare` warnings.
2 parents 9891f55 + feae279 commit e6d1856

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
484484

485485
if (ArgsCstrBuff != nullptr) {
486486
#if LLVM_VERSION_GE(20, 0)
487-
int buffer_offset = 0;
487+
size_t buffer_offset = 0;
488488
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
489489
auto Arg0 = std::string(ArgsCstrBuff);
490490
buffer_offset = Arg0.size() + 1;
@@ -502,7 +502,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
502502
Options.MCOptions.Argv0 = Arg0;
503503
Options.MCOptions.CommandlineArgs = CommandlineArgs;
504504
#else
505-
int buffer_offset = 0;
505+
size_t buffer_offset = 0;
506506
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
507507

508508
const size_t arg0_len = std::strlen(ArgsCstrBuff);
@@ -511,13 +511,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
511511
arg0[arg0_len] = '\0';
512512
buffer_offset += arg0_len + 1;
513513

514-
const int num_cmd_arg_strings = std::count(
514+
const size_t num_cmd_arg_strings = std::count(
515515
&ArgsCstrBuff[buffer_offset], &ArgsCstrBuff[ArgsCstrBuffLen], '\0');
516516

517517
std::string *cmd_arg_strings = new std::string[num_cmd_arg_strings];
518-
for (int i = 0; i < num_cmd_arg_strings; ++i) {
518+
for (size_t i = 0; i < num_cmd_arg_strings; ++i) {
519519
assert(buffer_offset < ArgsCstrBuffLen);
520-
const int len = std::strlen(ArgsCstrBuff + buffer_offset);
520+
const size_t len = std::strlen(ArgsCstrBuff + buffer_offset);
521521
cmd_arg_strings[i] = std::string(&ArgsCstrBuff[buffer_offset], len);
522522
buffer_offset += len + 1;
523523
}

0 commit comments

Comments
 (0)