<div dir="ltr">On Thu, May 30, 2013 at 2:00 AM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@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">
Author: ruiu<br>
Date: Thu May 30 01:00:10 2013<br>
New Revision: 182912<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=182912&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=182912&view=rev</a><br>
Log:<br>
[WinLink][Driver] Handle file extensions and defualt output file name.<br>
<br>
Modified:<br>
    lld/trunk/lib/Driver/WinLinkDriver.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=182912&r1=182911&r2=182912&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=182912&r1=182911&r2=182912&view=diff</a><br>

==============================================================================<br>
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)<br>
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu May 30 01:00:10 2013<br>
@@ -16,6 +16,7 @@<br>
 #include "llvm/ADT/StringSwitch.h"<br>
 #include "llvm/Option/Arg.h"<br>
 #include "llvm/Option/Option.h"<br>
+#include "llvm/Support/PathV2.h"<br>
<br>
 #include "lld/Driver/Driver.h"<br>
 #include "lld/ReaderWriter/PECOFFTargetInfo.h"<br>
@@ -72,6 +73,21 @@ llvm::COFF::WindowsSubsystem strToWinSub<br>
       .Default(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN);<br>
 }<br>
<br>
+// Add ".obj" extension if the given path name has no file extension.<br>
+StringRef canonicalizeInputFileName(StringRef path) {<br>
+  if (llvm::sys::path::extension(path).empty())<br>
+    return path.str() + ".obj";<br></blockquote><div><br></div><div style>Isn't this a use-after-return?  path.str() makes a temp std::string, which is concatenated.  Then we construct the StringRef from the string.</div>
<div style><br></div><div style>Probably the right thing is to take a std::string& and modify it in place.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  return path;<br>
+}<br>
+<br>
+// Replace a file extension with ".exe". If the given file has no<br>
+// extension, just add ".exe".<br>
+StringRef getDefaultOutputFileName(StringRef path) {<br>
+  StringRef ext = llvm::sys::path::extension(path);<br>
+  StringRef filename = ext.empty() ? path : path.drop_back(ext.size());<br>
+  return filename.str() + ".exe";<br></blockquote><div><br></div><div style>ditto?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
 } // namespace<br>
<br>
<br>
@@ -141,16 +157,26 @@ bool WinLinkDriver::parse(int argc, cons<br>
     info.setOutputPath(outpath->getValue());<br>
<br>
   // Add input files<br>
+  std::vector<StringRef> inputPaths;<br>
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT),<br>
                                ie = parsedArgs->filtered_end();<br>
        it != ie; ++it) {<br>
-    info.appendInputFile((*it)->getValue());<br>
+    inputPaths.push_back((*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>
-      info.appendInputFile(argv[i]);<br>
+      inputPaths.push_back(argv[i]);<br>
+<br>
+  // Add ".obj" extension for those who have no file extension.<br>
+  for (const StringRef &path : inputPaths)<br>
+    info.appendInputFile(canonicalizeInputFileName(path));<br>
+<br>
+  // If -out option was not specified, the default output file name is<br>
+  // constructed by replacing an extension with ".exe".<br>
+  if (info.outputPath().empty() && !inputPaths.empty())<br>
+    info.setOutputPath(getDefaultOutputFileName(inputPaths[0]));<br>
<br>
   // Validate the combination of options used.<br>
   return info.validate(diagnostics);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">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>