[lld] r187534 - Revert "[PECOFF][Driver] Remove quotes from command line arguments."

Rui Ueyama ruiu at google.com
Wed Jul 31 15:13:15 PDT 2013


Author: ruiu
Date: Wed Jul 31 17:13:15 2013
New Revision: 187534

URL: http://llvm.org/viewvc/llvm-project?rev=187534&view=rev
Log:
Revert "[PECOFF][Driver] Remove quotes from command line arguments."

This reverts commit r187390 because we should not handle argv's quotes ourselves.

In Windows, unlike Unix, quotes are not processed by the shell. Instead the C
startup routine parses it as described in
http://msdn.microsoft.com/en-us/library/a1y7w461.aspx and pass the results to
main(). So, at the time when the control reaches main(), quotes that should be
removed has already been removed.

We still need to handle quotes in the response file and in .drectve section
ourselves. That will be addressed in different patches.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=187534&r1=187533&r2=187534&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Wed Jul 31 17:13:15 2013
@@ -216,14 +216,6 @@ std::vector<StringRef> splitPathList(Str
   return std::move(ret);
 }
 
-// Removes surrounding single or double quotes from the string. If it's not
-// quoted, return the argument as is.
-StringRef unquote(StringRef str) {
-  bool isQuoted = (str.startswith("\"") && str.endswith("\"")) ||
-      (str.startswith("'") && str.endswith("'"));
-  return isQuoted ? str.substr(1, str.size() - 2) : str;
-}
-
 // Handle /failifmatch option.
 bool handleFailIfMismatchOption(StringRef option,
                                 std::map<StringRef, StringRef> &mustMatch,
@@ -353,33 +345,33 @@ bool WinLinkDriver::parse(int argc, cons
 
   // handle /base
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_base))
-    if (!parseBaseOption(info, unquote(arg->getValue()), diagnostics))
+    if (!parseBaseOption(info, arg->getValue(), diagnostics))
       return true;
 
   // handle /stack
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_stack))
-    if (!parseStackOption(info, unquote(arg->getValue()), diagnostics))
+    if (!parseStackOption(info, arg->getValue(), diagnostics))
       return true;
 
   // handle /heap
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_heap))
-    if (!parseHeapOption(info, unquote(arg->getValue()), diagnostics))
+    if (!parseHeapOption(info, arg->getValue(), diagnostics))
       return true;
 
   // handle /subsystem
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem))
-    if (!parseSubsystemOption(info, unquote(arg->getValue()), diagnostics))
+    if (!parseSubsystemOption(info, arg->getValue(), diagnostics))
       return true;
 
   // handle /entry
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_entry))
-    info.setEntrySymbolName(unquote(arg->getValue()));
+    info.setEntrySymbolName(arg->getValue());
 
   // handle /libpath
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_libpath),
                                ie = parsedArgs->filtered_end();
        it != ie; ++it) {
-    info.appendInputSearchPath(unquote((*it)->getValue()));
+    info.appendInputSearchPath((*it)->getValue());
   }
 
   // handle /force
@@ -406,19 +398,19 @@ bool WinLinkDriver::parse(int argc, cons
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_incl),
                                ie = parsedArgs->filtered_end();
        it != ie; ++it) {
-    info.addInitialUndefinedSymbol(unquote((*it)->getValue()));
+    info.addInitialUndefinedSymbol((*it)->getValue());
   }
 
   // handle /out
   if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out))
-    info.setOutputPath(unquote(outpath->getValue()));
+    info.setOutputPath(outpath->getValue());
 
   // handle /defaultlib
   std::vector<StringRef> defaultLibs;
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_defaultlib),
                                ie = parsedArgs->filtered_end();
        it != ie; ++it) {
-    defaultLibs.push_back(unquote((*it)->getValue()));
+    defaultLibs.push_back((*it)->getValue());
   }
 
   // Handle /failifmismatch. /failifmismatch is the hidden linker option behind
@@ -434,8 +426,7 @@ bool WinLinkDriver::parse(int argc, cons
            it = parsedArgs->filtered_begin(OPT_failifmismatch),
            ie = parsedArgs->filtered_end();
        it != ie; ++it) {
-    if (!handleFailIfMismatchOption(unquote((*it)->getValue()),
-                                    mustMatch, diagnostics))
+    if (!handleFailIfMismatchOption((*it)->getValue(), mustMatch, diagnostics))
       return true;
   }
 
@@ -444,13 +435,13 @@ bool WinLinkDriver::parse(int argc, cons
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT),
                                ie = parsedArgs->filtered_end();
        it != ie; ++it) {
-    inputPaths.push_back(unquote((*it)->getValue()));
+    inputPaths.push_back((*it)->getValue());
   }
 
   // Arguments after "--" are also input files
   if (doubleDashPosition > 0)
     for (int i = doubleDashPosition + 1; i < argc; ++i)
-      inputPaths.push_back(unquote(argv[i]));
+      inputPaths.push_back(argv[i]);
 
   // Add input files specified via the command line.
   for (const StringRef path : inputPaths)

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=187534&r1=187533&r2=187534&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Wed Jul 31 17:13:15 2013
@@ -66,16 +66,6 @@ TEST_F(WinLinkParserTest, UnixStyleOptio
   EXPECT_EQ("a.obj", inputFile(0));
 }
 
-TEST_F(WinLinkParserTest, Quote) {
-  EXPECT_FALSE(parse("link.exe", "/subsystem:\"console\"", "-out:'a.exe'",
-                     "/defaultlib:'user32.lib'", "'a.obj'", nullptr));
-  EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
-  EXPECT_EQ("a.exe", _info.outputPath());
-  EXPECT_EQ(2, inputFileCount());
-  EXPECT_EQ("a.obj", inputFile(0));
-  EXPECT_EQ("user32.lib", inputFile(1));
-}
-
 TEST_F(WinLinkParserTest, Mllvm) {
   EXPECT_FALSE(parse("link.exe", "-mllvm", "-debug", "a.obj", nullptr));
   const std::vector<const char *> &options = _info.llvmOptions();
@@ -215,7 +205,7 @@ TEST_F(WinLinkParserTest, NoInputFiles)
 
 TEST_F(WinLinkParserTest, FailIfMismatch_Match) {
   EXPECT_FALSE(parse("link.exe", "/failifmismatch:foo=bar",
-                     "/failifmismatch:\"foo=bar\"", "/failifmismatch:abc=def",
+                     "/failifmismatch:foo=bar", "/failifmismatch:abc=def",
                      "a.out", nullptr));
 }
 





More information about the llvm-commits mailing list