Skip to content

Commit

Permalink
Quote embedded codeview command line arguments
Browse files Browse the repository at this point in the history
The formatting of the command line arguments has been moved to the
frontend in:
llvm/llvm-project@e190d07

However, the Rust logic introduced in
rust-lang@ad0eceb
did not replicate the previous argument quoting behavior.
  • Loading branch information
nikic committed Feb 3, 2025
1 parent 9539a55 commit ee8284e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
Expand Down Expand Up @@ -472,16 +473,19 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
auto Arg0 = std::string(ArgsCstrBuff);
buffer_offset = Arg0.size() + 1;
auto ArgsCppStr = std::string(ArgsCstrBuff + buffer_offset,
ArgsCstrBuffLen - buffer_offset);
auto i = 0;
while (i != std::string::npos) {
i = ArgsCppStr.find('\0', i + 1);
if (i != std::string::npos)
ArgsCppStr.replace(i, 1, " ");

std::string CommandlineArgs;
raw_string_ostream OS(CommandlineArgs);
ListSeparator LS(" ");
for (StringRef Arg : split(StringRef(ArgsCstrBuff + buffer_offset,
ArgsCstrBuffLen - buffer_offset),
'\0')) {
OS << LS;
sys::printArg(OS, Arg, /*Quote=*/true);
}
OS.flush();
Options.MCOptions.Argv0 = Arg0;
Options.MCOptions.CommandlineArgs = ArgsCppStr;
Options.MCOptions.CommandlineArgs = CommandlineArgs;
#else
int buffer_offset = 0;
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
Expand Down

0 comments on commit ee8284e

Please sign in to comment.