<div dir="ltr">On Mon, Jul 29, 2013 at 4:53 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">The correct unquoting mechanism is probably the one used by CommandLineToArgv(W).<div><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx</a></div>


<div><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx</a><br><div><br><div>There's a FIXME to implement this algorithm in llvm/lib/Support/CommandLine.cpp in TokenizeWindowsCommandLine().</div>

</div></div></div></blockquote><div><br></div><div>Thanks, Reid. I think that's what I needed for .drective section. I'll implement that function.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><div>
</div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 29, 2013 at 4:32 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Mon Jul 29 18:32:22 2013<br>
New Revision: 187390<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=187390&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=187390&view=rev</a><br>
Log:<br>
[PECOFF][Driver] Remove quotes from command line arguments.<br>
<br>
The command line option in .drectve section may be quoted by double<br>
quotes, and if that's the case we have to remove them.<br>
<br>
Modified:<br>
    lld/trunk/lib/Driver/WinLinkDriver.cpp<br>
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp<br>
<br>
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=187390&r1=187389&r2=187390&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=187390&r1=187389&r2=187390&view=diff</a><br>



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



==============================================================================<br>
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)<br>
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Jul 29 18:32:22 2013<br>
@@ -66,6 +66,16 @@ TEST_F(WinLinkParserTest, UnixStyleOptio<br>
   EXPECT_EQ("a.obj", inputFile(0));<br>
 }<br>
<br>
+TEST_F(WinLinkParserTest, Quote) {<br>
+  EXPECT_FALSE(parse("link.exe", "/subsystem:\"console\"", "-out:'a.exe'",<br>
+                     "/defaultlib:'user32.lib'", "'a.obj'", nullptr));<br>
+  EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());<br>
+  EXPECT_EQ("a.exe", _info.outputPath());<br>
+  EXPECT_EQ(2, inputFileCount());<br>
+  EXPECT_EQ("a.obj", inputFile(0));<br>
+  EXPECT_EQ("user32.lib", inputFile(1));<br>
+}<br>
+<br>
 TEST_F(WinLinkParserTest, Mllvm) {<br>
   EXPECT_FALSE(parse("link.exe", "-mllvm", "-debug", "a.obj", nullptr));<br>
   const std::vector<const char *> &options = _info.llvmOptions();<br>
@@ -205,7 +215,7 @@ TEST_F(WinLinkParserTest, NoInputFiles)<br>
<br>
 TEST_F(WinLinkParserTest, FailIfMismatch_Match) {<br>
   EXPECT_FALSE(parse("link.exe", "/failifmismatch:foo=bar",<br>
-                     "/failifmismatch:foo=bar", "/failifmismatch:abc=def",<br>
+                     "/failifmismatch:\"foo=bar\"", "/failifmismatch:abc=def",<br>
                      "a.out", nullptr));<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>