<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 1, 2016 at 6:48 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Feb 1, 2016 at 6:45 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, Feb 1, 2016 at 6:36 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Mon, Feb 1, 2016 at 6:29 PM, Rui Ueyama via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: ruiu<br>
Date: Mon Feb  1 20:29:03 2016<br>
New Revision: 259455<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259455&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259455&view=rev</a><br>
Log:<br>
Replace auto with the real type.<br>
<br>
Modified:<br>
    lld/trunk/ELF/OutputSections.cpp<br>
<br>
Modified: lld/trunk/ELF/OutputSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=259455&r1=259454&r2=259455&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=259455&r1=259454&r2=259455&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.cpp Mon Feb  1 20:29:03 2016<br>
@@ -144,7 +144,7 @@ template <class ELFT> void GotSection<EL<br>
<br>
 template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) {<br>
   Target->writeGotHeader(Buf);<br>
-  for (const auto &L : MipsLocalGotPos) {<br>
+  for (std::pair<uintX_t, size_t> &L : MipsLocalGotPos) {<br></blockquote><div><br></div></span><div>This is probably accidentally causing a copy, because the value type of a map is usually std::pair<const K, V> - so this sort of for loop introduces an implicit conversion and then causes local reference extension to occur (Clang has a warning for this - so I hope this is triggering a warning)<br><br>This is one of the reasons auto is particularly encouraged in places like this - to avoid the possibility of mismatching with the type (though Clang's warning makes this a less risky proposition)</div></div></div></div></blockquote><div><br></div></span><div>Thank you for pointing that out. What's the best practice here? Just use auto and immediately assign both values in a pair to some variables (to give them names)?</div></div></div></div></blockquote><div><br></div></span><div>If the name/use of the map is not sufficient for the code to make sense (eg: if the map is a class member, but used infrequently enough that anyone looking at the class would have a clear idea of the key and value) as-is, I'm not sure there's any particular best practice.<br><br>If the type information is particularly informative - maybe leaving it as-is (& fixing the const) might suffice, if the Clang warning is doing its job (are you using Clang to build? You might need to rebuild your host Clang compiler, maybe?).<br><br>But alternatively, yes, it's not entirely uncommon to declare a couple of references to the key and value to give them informative names (and/or type information).<br></div></div></div></div></blockquote><div><br></div><div>You mentioned about declaring a couple of references because the value may be a large value, right? In this case the values are both 64 or 32 bit integers, so I'd write</div><div><br></div><div><div>  for (const auto &L : MipsLocalGotPos) {</div><div>    uintX_t GotValue = L.first;</div><div>    size_t GotIndex = L.second;</div><div>    uint8_t *Entry = Buf + GotIndex* sizeof(uintX_t);</div><div>    write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, GotValue);</div><div>  }</div></div><div><br></div><div>instead of</div><div><br></div><div><div>  for (const auto &L : MipsLocalGotPos) {</div><div>    uintX_t &GotValue = L.first; // <-- has &</div><div>    size_t &GotIndex = L.second;</div><div>    uint8_t *Entry = Buf + L.second * sizeof(uintX_t);</div><div>    write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, L.first);</div><div>  }</div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br>- Dave</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
     uint8_t *Entry = Buf + L.second * sizeof(uintX_t);<br>
     write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, L.first);<br>
   }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>