[PATCH] D43988: Fix processing of path names in response files on Windows

Dmitry Mikulin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 16:52:20 PST 2018


dmikulin created this revision.
dmikulin added a reviewer: Bigcheese.
Herald added a subscriber: hiraditya.

On Windows we need to be able to process response files with Windows-style path names which include backslashes.


https://reviews.llvm.org/D43988

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
@@ -10,6 +10,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -631,6 +632,31 @@
   EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
 }
 
+TEST(CommandLineTest, ResponseFileWindows) {
+  if (Triple(sys::getProcessTriple()).getOS() != Triple::Win32)
+    return;
+
+  static cl::list<std::string>
+	  InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
+  StackOption<bool> TopLevelOpt("top-level", cl::init(false));
+
+  // Create response file.
+  std::ofstream RspFile("resp");
+  EXPECT_TRUE(RspFile.is_open());
+  RspFile << "-top-level\npath\\dir\\file1\npath/dir/file2";
+  RspFile.close();
+
+  const char *args[] = {"prog", "@resp"};
+  EXPECT_FALSE(TopLevelOpt);
+  EXPECT_TRUE(
+      cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls()));
+  EXPECT_TRUE(TopLevelOpt);
+  EXPECT_TRUE(InputFilenames[0] == "path\\dir\\file1");
+  EXPECT_TRUE(InputFilenames[1] == "path/dir/file2");
+
+  llvm::sys::fs::remove("resp");
+}
+
 TEST(CommandLineTest, ResponseFiles) {
   llvm::SmallString<128> TestDir;
   std::error_code EC =
Index: llvm/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -1080,7 +1081,10 @@
   SmallVector<const char *, 20> newArgv(argv, argv + argc);
   BumpPtrAllocator A;
   StringSaver Saver(A);
-  ExpandResponseFiles(Saver, TokenizeGNUCommandLine, newArgv);
+  ExpandResponseFiles(Saver,
+         (Triple(sys::getProcessTriple()).getOS() == Triple::Win32) ?
+         cl::TokenizeWindowsCommandLine : cl::TokenizeGNUCommandLine,
+         newArgv);
   argv = &newArgv[0];
   argc = static_cast<int>(newArgv.size());
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43988.136644.patch
Type: text/x-patch
Size: 2398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/0ca47156/attachment.bin>


More information about the llvm-commits mailing list