diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1009,7 +1009,7 @@ } } - if (!Token.empty()) + if (State == UNQUOTED) AddToken(Saver.save(Token.str())); } diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -253,8 +253,8 @@ } TEST(CommandLineTest, TokenizeWindowsCommandLine1) { - const char Input[] = "a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr " - "\"st \\\"u\" \\v"; + const char Input[] = + R"(a\b c\\d e\\"f g" h\"i j\\\"k "lmn" o pqr "st \"u" \v)"; const char *const Output[] = { "a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k", "lmn", "o", "pqr", "st \"u", "\\v" }; testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output, @@ -268,6 +268,17 @@ array_lengthof(Output)); } +TEST(CommandLineTest, TokenizeWindowsCommandLineQuotedLastArgument) { + const char Input1[] = R"(a b c d "")"; + const char *const Output1[] = {"a", "b", "c", "d", ""}; + testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input1, Output1, + array_lengthof(Output1)); + const char Input2[] = R"(a b c d ")"; + const char *const Output2[] = {"a", "b", "c", "d"}; + testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input2, Output2, + array_lengthof(Output2)); +} + TEST(CommandLineTest, TokenizeConfigFile1) { const char *Input = "\\"; const char *const Output[] = { "\\" };