[llvm] r224003 - Use unique_ptr to remove an explicit delete. Change return type to pass the unique_ptr to caller.

David Blaikie dblaikie at gmail.com
Thu Dec 11 10:00:23 PST 2014


On Wed, Dec 10, 2014 at 11:04 PM, Craig Topper <craig.topper at gmail.com>
wrote:

> Author: ctopper
> Date: Thu Dec 11 01:04:46 2014
> New Revision: 224003
>
> URL: http://llvm.org/viewvc/llvm-project?rev=224003&view=rev
> Log:
> Use unique_ptr to remove an explicit delete. Change return type to pass
> the unique_ptr to caller.
>
> Modified:
>     llvm/trunk/tools/llc/llc.cpp
>
> Modified: llvm/trunk/tools/llc/llc.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=224003&r1=224002&r2=224003&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llc/llc.cpp (original)
> +++ llvm/trunk/tools/llc/llc.cpp Thu Dec 11 01:04:46 2014
> @@ -95,9 +95,9 @@ static cl::opt<bool> AsmVerbose("asm-ver
>
>  static int compileModule(char **, LLVMContext &);
>
> -static tool_output_file *GetOutputStream(const char *TargetName,
> -                                         Triple::OSType OS,
> -                                         const char *ProgName) {
> +static std::unique_ptr<tool_output_file>
> +GetOutputStream(const char *TargetName, Triple::OSType OS,
> +                const char *ProgName) {
>    // If we don't yet have an output filename, make one.
>    if (OutputFilename.empty()) {
>      if (InputFilename == "-")
> @@ -151,10 +151,10 @@ static tool_output_file *GetOutputStream
>    sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
>    if (!Binary)
>      OpenFlags |= sys::fs::F_Text;
> -  tool_output_file *FDOut = new tool_output_file(OutputFilename, EC,
> OpenFlags);
> +  auto FDOut = llvm::make_unique<tool_output_file>(OutputFilename, EC,
> +                                                   OpenFlags);
>    if (EC) {
>      errs() << EC.message() << '\n';
> -    delete FDOut;
>      return nullptr;
>    }
>

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:

  unique_ptr<T> p(func());

to

  unique_ptr<T> p = func();

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).

- David


>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141211/46d74a1d/attachment.html>


More information about the llvm-commits mailing list