<div dir="ltr">Ah, I just hit that myself while working on the type units in llvm-dwp.<br><br>SetVector does have toArrayRef which is probably the better option than what you have (what you have there would be UB if the container is empty, for example).<br><br>But yeah, I wouldn't mind if SetVector just had an "operator ArrayRef<T>". That seems reasonable, unambiguous, obvious goodness.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 5:27 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 13 December 2015 at 19:13, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
> On Thu, Dec 10, 2015 at 8:35 AM, Rafael Espindola via llvm-commits<br>
> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>><br>
>> Author: rafael<br>
>> Date: Thu Dec 10 10:35:06 2015<br>
>> New Revision: 255258<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255258&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255258&view=rev</a><br>
>> Log:<br>
>> Avoid undefined behavior when vector is empty.<br>
>><br>
>> Found by ubsan.<br>
>><br>
>> Modified:<br>
>>     llvm/trunk/include/llvm/ADT/SetVector.h<br>
>>     llvm/trunk/lib/Linker/LinkModules.cpp<br>
>><br>
>> Modified: llvm/trunk/include/llvm/ADT/SetVector.h<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SetVector.h?rev=255258&r1=255257&r2=255258&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SetVector.h?rev=255258&r1=255257&r2=255258&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/include/llvm/ADT/SetVector.h (original)<br>
>> +++ llvm/trunk/include/llvm/ADT/SetVector.h Thu Dec 10 10:35:06 2015<br>
>> @@ -58,6 +58,8 @@ public:<br>
>>      insert(Start, End);<br>
>>    }<br>
>><br>
>> +  ArrayRef<T> getArrayRef() const { return vector_; }<br>
>> +<br>
>>    /// \brief Determine if the SetVector is empty or not.<br>
>>    bool empty() const {<br>
>>      return vector_.empty();<br>
>><br>
>> Modified: llvm/trunk/lib/Linker/LinkModules.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=255258&r1=255257&r2=255258&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=255258&r1=255257&r2=255258&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/Linker/LinkModules.cpp (original)<br>
>> +++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Dec 10 10:35:06 2015<br>
>> @@ -772,8 +772,7 @@ bool ModuleLinker::run() {<br>
>>        Internalize.insert(GV->getName());<br>
>>    }<br>
>><br>
>> -  if (Mover.move(SrcM,<br>
>> -                 makeArrayRef(&*ValuesToLink.begin(),<br>
>> ValuesToLink.size()),<br>
><br>
><br>
> Isn't vector already implicitly convertible to ArrayRef? (I guess there's<br>
> something else at work heer - 'move' is a function template & has weird arg<br>
> deduction issues? something else?)<br>
<br>
</div></div>ValuesToLink is a SetVector which is not implicitly convertible to<br>
ArrayRef. Should it be?<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div>