[llvm] r212403 - Declare variable on first use.

Alp Toker alp at nuanti.com
Mon Jul 7 16:45:33 PDT 2014


On 08/07/2014 02:05, David Blaikie wrote:
> I see you've been playing around with LTO/createFromBuffer - any
> chance of createFromBuffer returning by value (possibly Optional<T> or
> ErrorOr<T> so it can return the invalid result) or std::unique_ptr?
> Reason it can't? (just seeing those raw pointers & wondering)

Surely create* functions other allocation functions should return raw 
pointers, leaving it up to the caller how to adopt them?

This is built right into the C++ programming language (new/delete), 
verifiable using all kinds of checkers and instantly recognisable to C 
and C++ developers.

I'm really not keen on wrapping these return types in multiple layers of 
templates, and I don't think anyone seriously thinks the current 
situation ErrorOr<std::unique_ptr<MemoryBuffer>> is turning out well.

Ultimately every raw pointer in the codebase could be wrapped with some 
kind of smart pointer, but it'd achieve little other than wearing down < 
and > keys, so let's avoid going that way.

Alp.


>
> On Sun, Jul 6, 2014 at 7:31 AM, Rafael Espindola
> <rafael.espindola at gmail.com> wrote:
>> Author: rafael
>> Date: Sun Jul  6 09:31:22 2014
>> New Revision: 212403
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=212403&view=rev
>> Log:
>> Declare variable on first use.
>>
>> Modified:
>>      llvm/trunk/tools/gold/gold-plugin.cpp
>>
>> Modified: llvm/trunk/tools/gold/gold-plugin.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=212403&r1=212402&r2=212403&view=diff
>> ==============================================================================
>> --- llvm/trunk/tools/gold/gold-plugin.cpp (original)
>> +++ llvm/trunk/tools/gold/gold-plugin.cpp Sun Jul  6 09:31:22 2014
>> @@ -261,12 +261,11 @@ ld_plugin_status onload(ld_plugin_tv *tv
>>     return LDPS_OK;
>>   }
>>
>> -/// claim_file_hook - called by gold to see whether this file is one that
>> -/// our plugin can handle. We'll try to open it and register all the symbols
>> -/// with add_symbol if possible.
>> +/// Called by gold to see whether this file is one that our plugin can handle.
>> +/// We'll try to open it and register all the symbols with add_symbol if
>> +/// possible.
>>   static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
>>                                           int *claimed) {
>> -  LTOModule *M;
>>     const void *view;
>>     std::unique_ptr<MemoryBuffer> buffer;
>>     if (get_view) {
>> @@ -293,7 +292,8 @@ static ld_plugin_status claim_file_hook(
>>       return LDPS_OK;
>>
>>     std::string Error;
>> -  M = LTOModule::createFromBuffer(view, file->filesize, TargetOpts, Error);
>> +  LTOModule *M =
>> +      LTOModule::createFromBuffer(view, file->filesize, TargetOpts, Error);
>>     if (!M) {
>>       (*message)(LDPL_ERROR,
>>                  "LLVM gold plugin has failed to create LTO module: %s",
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-- 
http://www.nuanti.com
the browser experts




More information about the llvm-commits mailing list