Index: llvm/trunk/lib/Support/CommandLine.cpp =================================================================== --- llvm/trunk/lib/Support/CommandLine.cpp +++ llvm/trunk/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 newArgv(argv, argv + argc); BumpPtrAllocator A; StringSaver Saver(A); - ExpandResponseFiles(Saver, TokenizeGNUCommandLine, newArgv); + ExpandResponseFiles(Saver, + Triple(sys::getProcessTriple()).isOSWindows() ? + cl::TokenizeWindowsCommandLine : cl::TokenizeGNUCommandLine, + newArgv); argv = &newArgv[0]; argc = static_cast(newArgv.size()); Index: llvm/trunk/unittests/Support/CommandLineTest.cpp =================================================================== --- llvm/trunk/unittests/Support/CommandLineTest.cpp +++ llvm/trunk/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,40 @@ EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data())); } +TEST(CommandLineTest, ResponseFileWindows) { + if (!Triple(sys::getProcessTriple()).isOSWindows()) + return; + + static cl::list + InputFilenames(cl::Positional, cl::desc(""), cl::ZeroOrMore); + StackOption TopLevelOpt("top-level", cl::init(false)); + + // Create response file. + int FileDescriptor; + SmallString<64> TempPath; + std::error_code EC = + llvm::sys::fs::createTemporaryFile("resp-", ".txt", FileDescriptor, TempPath); + EXPECT_TRUE(!EC); + + std::ofstream RspFile(TempPath.c_str()); + EXPECT_TRUE(RspFile.is_open()); + RspFile << "-top-level\npath\\dir\\file1\npath/dir/file2"; + RspFile.close(); + + llvm::SmallString<128> RspOpt; + RspOpt.append(1, '@'); + RspOpt.append(TempPath.c_str()); + const char *args[] = {"prog", RspOpt.c_str()}; + 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(TempPath.c_str()); +} + TEST(CommandLineTest, ResponseFiles) { llvm::SmallString<128> TestDir; std::error_code EC =