Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1f9a018

Browse files
committed
Auto merge of rust-lang#130446 - durin42:llvm-20-fix-CommandLineArgs, r=workingjubilee
rustc_llvm: adapt to flattened CLI args in LLVM This changed in llvm/llvm-project@e190d07. I decided to stick with more duplication between the ifdef blocks to make the code easier to read for the next two years before we can plausibly drop LLVM 19. `@rustbot` label: +llvm-main try-job: x86_64-msvc
2 parents 6ce3767 + 86d67b7 commit 1f9a018

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
485485
Options.EmitStackSizeSection = EmitStackSizeSection;
486486

487487
if (ArgsCstrBuff != nullptr) {
488+
#if LLVM_VERSION_GE(20, 0)
489+
int buffer_offset = 0;
490+
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '0円');
491+
auto Arg0 = std::string(ArgsCstrBuff);
492+
buffer_offset = Arg0.size() + 1;
493+
auto ArgsCppStr =
494+
std::string(ArgsCstrBuff + buffer_offset, ArgsCstrBuffLen - 1);
495+
auto i = 0;
496+
while (i != std::string::npos) {
497+
i = ArgsCppStr.find('0円', i + 1);
498+
if (i != std::string::npos)
499+
ArgsCppStr.replace(i, i + 1, " ");
500+
}
501+
Options.MCOptions.Argv0 = Arg0;
502+
Options.MCOptions.CommandlineArgs = ArgsCppStr;
503+
#else
488504
int buffer_offset = 0;
489505
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '0円');
490506

@@ -510,6 +526,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
510526
Options.MCOptions.Argv0 = arg0;
511527
Options.MCOptions.CommandLineArgs =
512528
llvm::ArrayRef<std::string>(cmd_arg_strings, num_cmd_arg_strings);
529+
#endif
513530
}
514531

515532
TargetMachine *TM = TheTarget->createTargetMachine(
@@ -518,10 +535,11 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
518535
}
519536

520537
extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
521-
538+
#if LLVM_VERSION_LT(20, 0)
522539
MCTargetOptions &MCOptions = unwrap(TM)->Options.MCOptions;
523540
delete[] MCOptions.Argv0;
524541
delete[] MCOptions.CommandLineArgs.data();
542+
#endif
525543

526544
delete unwrap(TM);
527545
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /