<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 10, 2014 at 11:04 PM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ctopper<br>
Date: Thu Dec 11 01:04:46 2014<br>
New Revision: 224003<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224003&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=224003&view=rev</a><br>
Log:<br>
Use unique_ptr to remove an explicit delete. Change return type to pass the unique_ptr to caller.<br>
<br>
Modified:<br>
    llvm/trunk/tools/llc/llc.cpp<br>
<br>
Modified: llvm/trunk/tools/llc/llc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=224003&r1=224002&r2=224003&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=224003&r1=224002&r2=224003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llc/llc.cpp (original)<br>
+++ llvm/trunk/tools/llc/llc.cpp Thu Dec 11 01:04:46 2014<br>
@@ -95,9 +95,9 @@ static cl::opt<bool> AsmVerbose("asm-ver<br>
<br>
 static int compileModule(char **, LLVMContext &);<br>
<br>
-static tool_output_file *GetOutputStream(const char *TargetName,<br>
-                                         Triple::OSType OS,<br>
-                                         const char *ProgName) {<br>
+static std::unique_ptr<tool_output_file><br>
+GetOutputStream(const char *TargetName, Triple::OSType OS,<br>
+                const char *ProgName) {<br>
   // If we don't yet have an output filename, make one.<br>
   if (OutputFilename.empty()) {<br>
     if (InputFilename == "-")<br>
@@ -151,10 +151,10 @@ static tool_output_file *GetOutputStream<br>
   sys::fs::OpenFlags OpenFlags = sys::fs::F_None;<br>
   if (!Binary)<br>
     OpenFlags |= sys::fs::F_Text;<br>
-  tool_output_file *FDOut = new tool_output_file(OutputFilename, EC, OpenFlags);<br>
+  auto FDOut = llvm::make_unique<tool_output_file>(OutputFilename, EC,<br>
+                                                   OpenFlags);<br>
   if (EC) {<br>
     errs() << EC.message() << '\n';<br>
-    delete FDOut;<br>
     return nullptr;<br>
   }<br></blockquote><div><br>I'm assuming the callers of this function didn't need updating because they were already using unique_ptr and unique_ptr's T* ctor? It'd be nice to update those callers from this:<br><br>  unique_ptr<T> p(func());<br><br>to<br><br>  unique_ptr<T> p = func();<br><br>when func changes return type from T* to unique_ptr<T> to help indicate that there's no explicit conversion going on anymore (makes the code look (and be) a bit 'safer' imho).<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>