Skip to content

Commit 97f6e4d

Browse files
committed
Quote embedded codeview command line arguments
The formatting of the command line arguments has been moved to the frontend in: llvm/llvm-project@e190d07 However, the Rust logic introduced in ad0eceb did not replicate the previous argument quoting behavior.
1 parent bf3e787 commit 97f6e4d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/Passes/StandardInstrumentations.h"
2323
#include "llvm/Support/CBindingWrapping.h"
2424
#include "llvm/Support/FileSystem.h"
25+
#include "llvm/Support/Program.h"
2526
#include "llvm/Support/TimeProfiler.h"
2627
#include "llvm/Support/VirtualFileSystem.h"
2728
#include "llvm/Target/TargetMachine.h"
@@ -472,16 +473,19 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
472473
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
473474
auto Arg0 = std::string(ArgsCstrBuff);
474475
buffer_offset = Arg0.size() + 1;
475-
auto ArgsCppStr = std::string(ArgsCstrBuff + buffer_offset,
476-
ArgsCstrBuffLen - buffer_offset);
477-
auto i = 0;
478-
while (i != std::string::npos) {
479-
i = ArgsCppStr.find('\0', i + 1);
480-
if (i != std::string::npos)
481-
ArgsCppStr.replace(i, 1, " ");
476+
477+
std::string CommandlineArgs;
478+
raw_string_ostream OS(CommandlineArgs);
479+
ListSeparator LS(" ");
480+
for (StringRef Arg : split(StringRef(ArgsCstrBuff + buffer_offset,
481+
ArgsCstrBuffLen - buffer_offset),
482+
'\0')) {
483+
OS << LS;
484+
sys::printArg(OS, Arg, /*Quote=*/true);
482485
}
486+
OS.flush();
483487
Options.MCOptions.Argv0 = Arg0;
484-
Options.MCOptions.CommandlineArgs = ArgsCppStr;
488+
Options.MCOptions.CommandlineArgs = CommandlineArgs;
485489
#else
486490
int buffer_offset = 0;
487491
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');

0 commit comments

Comments
 (0)