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 @@ -999,7 +999,7 @@ } } // Append the last token after hitting EOF with no whitespace. - if (!Token.empty()) + if (State == UNQUOTED) NewArgv.push_back(Saver.save(StringRef(Token)).data()); // Mark the end of response files if (MarkEOLs) 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,10 +253,12 @@ } 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 *const Output[] = { "a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k", - "lmn", "o", "pqr", "st \"u", "\\v" }; + const char Input[] = + "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, array_lengthof(Output)); }