Index: llvm/lib/Support/CommandLine.cpp =================================================================== --- llvm/lib/Support/CommandLine.cpp +++ llvm/lib/Support/CommandLine.cpp @@ -919,6 +919,14 @@ Token.push_back('"'); return I; } + + bool FollowedBySpace = (I != E && Src[I] == ' '); + if (FollowedBySpace && (BackslashCount % 2 == 1)) { + Token.append(BackslashCount - 1, '\\'); + Token.append(1, ' '); + return I; + } + Token.append(BackslashCount, '\\'); return I - 1; } Index: llvm/unittests/Support/CommandLineTest.cpp =================================================================== --- llvm/unittests/Support/CommandLineTest.cpp +++ llvm/unittests/Support/CommandLineTest.cpp @@ -239,6 +239,14 @@ array_lengthof(Output)); } +TEST(CommandLineTest, TokenizeWindowsCommandLine3) { + const char Input[] = "-o D:/work\\ folder\\ foo -o D:/work\\\\ folder"; + const char *const Output[] = {"-o", "D:/work folder foo", "-o", "D:/work\\\\", + "folder"}; + testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output, + array_lengthof(Output)); +} + TEST(CommandLineTest, TokenizeWindowsCommandLineQuotedLastArgument) { const char Input1[] = R"(a b c d "")"; const char *const Output1[] = {"a", "b", "c", "d", ""};