<div dir="rtl"><div dir="ltr">I'm not sure how std::equal of two nullptrs should be, is this documented or UB?</div><div dir="ltr"><br></div><div dir="ltr">Anyhow the question is what to return for the various combinatios of <span style="color:rgb(80,0,80);font-size:12.8000001907349px">element_begin() and </span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">Other->element_begin() being non/nullptr. What you wrote makes sense, </span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">we probably need something like</span></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div dir="ltr"><font face="monospace, monospace"><span style="color:rgb(80,0,80);font-size:12.8000001907349px">if (!element_begin()</span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">)</span><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></font></div><div dir="ltr"><font face="monospace, monospace"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"> return true</span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">;</span></font></div><div dir="ltr"><font face="monospace, monospace"><span style="color:rgb(80,0,80);font-size:12.8000001907349px">else</span></font></div><div dir="ltr"><font face="monospace, monospace"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"> return </span></font><font color="#500050" face="monospace, monospace"><span style="font-size:12.8000001907349px">std::equal(element_begin(), element_end(), Other->element_begin());</span></font></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px">(because other cases are already handled in the previous if)</span></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div dir="ltr">What do you think?</div><div dir="ltr">Also, how this could be tested?</div><div dir="ltr"><br></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div dir="ltr"><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">2015-08-12 0:04 GMT+03:00 Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span>:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(now cc'ing the new llvm-commits list)<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 11, 2015 at 2:01 PM, Hans Wennborg <<a href="mailto:hans@chromium.org">hans@chromium.org</a>> wrote:<br>
> On Tue, Aug 4, 2015 at 8:57 AM, Yaron Keren <<a href="mailto:yaron.keren@gmail.com">yaron.keren@gmail.com</a>> wrote:<br>
>> Author: yrnkrn<br>
>> Date: Tue Aug 4 10:57:04 2015<br>
>> New Revision: 243996<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=243996&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243996&view=rev</a><br>
>> Log:<br>
>> Avoid passing nullptr to std::equal.<br>
>> As documented in the LLVM Coding Standards, indeed MSVC incorrectly asserts<br>
>> on this in Debug mode. This happens when building clang with Visual C++ and<br>
>> -triple i686-pc-windows-gnu on these clang regression tests:<br>
>><br>
>> clang/test/CodeGen/2011-03-08-ZeroFieldUnionInitializer.c<br>
>> clang/test/CodeGen/empty-union-init.c<br>
><br>
> Should we merge this to 3.7?<br>
><br>
>> Modified: llvm/trunk/lib/IR/Type.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Type.cpp?rev=243996&r1=243995&r2=243996&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Type.cpp?rev=243996&r1=243995&r2=243996&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/IR/Type.cpp (original)<br>
>> +++ llvm/trunk/lib/IR/Type.cpp Tue Aug 4 10:57:04 2015<br>
>> @@ -612,7 +612,8 @@ bool StructType::isLayoutIdentical(Struc<br>
>> getNumElements() != Other->getNumElements())<br>
>> return false;<br>
>><br>
>> - return std::equal(element_begin(), element_end(), Other->element_begin());<br>
>> + return element_begin() &&<br>
>> + std::equal(element_begin(), element_end(), Other->element_begin());<br>
><br>
> Actually, wouldn't std::equal return true if element_begin() and<br>
> element_end() are both null? It seems the new code will now return<br>
> false for that case. If two StructTypes both have zero elements,<br>
> shouldn't they be considered as having identical layout?<br>
</div></div></blockquote></div><br></div>