[PATCH] D78346: Fix Windows command line bug when last token in response file is ""

Neil Dhar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 23:25:39 PDT 2020


neildhar created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Current state machine for parsing tokens from response files in Windows does not correctly handle the case where the last token is "".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78346

Files:
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp


Index: llvm/unittests/Support/CommandLineTest.cpp
===================================================================
--- llvm/unittests/Support/CommandLineTest.cpp
+++ 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));
 }
Index: llvm/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78346.258236.patch
Type: text/x-patch
Size: 1469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200417/a9eff8c4/attachment.bin>


More information about the llvm-commits mailing list