<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 17, 2015 at 5:35 PM, Artem Belevich <span dir="ltr"><<a href="mailto:tra@google.com" target="_blank">tra@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">getLibDeviceFile only used once per device-side compilation in driver, so returning the string should be OK here.<div><br></div><div><div>BTW, would copy elision kick in when I use std::string Path = getLibDeviceFile("foo"); ?</div></div></div></blockquote><div><br></div><div>Yeah - if the caller needs a copy anyway (if they're going to build a new string from it - appending things, etc) then, yeah, the API choice won't impact performance much/at all.<br><br>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br><div>--Artem</div></div></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Nov 17, 2015 at 5:12 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, Nov 17, 2015 at 4:37 PM, Artem Belevich via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: tra<br>
Date: Tue Nov 17 18:37:41 2015<br>
New Revision: 253410<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=253410&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=253410&view=rev</a><br>
Log:<br>
Fix for use-after-free which caused test failure in <a href="http://cuda-detect.cu" rel="noreferrer" target="_blank">cuda-detect.cu</a>.<br>
<br>
Return std::string itself instead StringRef to a temporary std::string.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Driver/ToolChains.h<br>
<br>
Modified: cfe/trunk/lib/Driver/ToolChains.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=253410&r1=253409&r2=253410&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=253410&r1=253409&r2=253410&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/ToolChains.h (original)<br>
+++ cfe/trunk/lib/Driver/ToolChains.h Tue Nov 17 18:37:41 2015<br>
@@ -186,7 +186,7 @@ protected:<br>
     /// \brief Get the detected Cuda device library path.<br>
     StringRef getLibDevicePath() const { return CudaLibDevicePath; }<br>
     /// \brief Get libdevice file for given architecture<br>
-    StringRef getLibDeviceFile(StringRef Gpu) const {<br>
+    std::string getLibDeviceFile(StringRef Gpu) const {<br>
       return CudaLibDeviceMap.lookup(Gpu);<br></blockquote><div><br></div></span><div>You could implement this as:<br><br>auto I = CudaLibDeviceMap.find(Gpu);<br>return I != CudaLibDeviceMap.end() ? I->second : "";<br><br>returning StringRef<br><br>Or, if you know the element will always be in the collection, you could just assert that and "return CudaLibDeviceMap[Gpu]; - and you could return const std::string& there, or StringRef, whichever.<br><br>(both/any of these options would avoid needing to allocate a new string to every caller)</div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     }<br>
   };<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></span></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr">--Artem Belevich</div></div>
</font></span></div>
</blockquote></div><br></div></div>