<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 5, 2017 at 8:02 AM Alexander Kornienko via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Tue Jul 4 08:13:02 2017<br>
New Revision: 307085<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=307085&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=307085&view=rev</a><br>
Log:<br>
Fix dangling StringRefs found by clang-tidy misc-dangling-handle check.<br>
<br>
Modified:<br>
llvm/trunk/tools/llvm-lto/llvm-lto.cpp<br>
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp<br>
<br>
Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=307085&r1=307084&r2=307085&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=307085&r1=307084&r2=307085&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)<br>
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Tue Jul 4 08:13:02 2017<br>
@@ -383,7 +383,7 @@ loadAllFilesForIndex(const ModuleSummary<br>
<br>
for (auto &ModPath : Index.modulePaths()) {<br>
const auto &Filename = ModPath.first();<br>
- auto CurrentActivity = "loading file '" + Filename + "'";<br>
+ std::string CurrentActivity = ("loading file '" + Filename + "'").str();<br>
auto InputOrErr = MemoryBuffer::getFile(Filename);<br>
error(InputOrErr, "error " + CurrentActivity);<br>
InputBuffers.push_back(std::move(*InputOrErr));<br>
@@ -475,7 +475,7 @@ private:<br>
std::vector<std::unique_ptr<MemoryBuffer>> InputBuffers;<br>
for (unsigned i = 0; i < InputFilenames.size(); ++i) {<br>
auto &Filename = InputFilenames[i];<br>
- StringRef CurrentActivity = "loading file '" + Filename + "'";<br>
+ std::string CurrentActivity = "loading file '" + Filename + "'";<br>
auto InputOrErr = MemoryBuffer::getFile(Filename);<br>
error(InputOrErr, "error " + CurrentActivity);<br>
InputBuffers.push_back(std::move(*InputOrErr));<br>
@@ -710,7 +710,7 @@ private:<br>
std::vector<std::unique_ptr<MemoryBuffer>> InputBuffers;<br>
for (unsigned i = 0; i < InputFilenames.size(); ++i) {<br>
auto &Filename = InputFilenames[i];<br>
- StringRef CurrentActivity = "loading file '" + Filename + "'";<br>
+ std::string CurrentActivity = "loading file '" + Filename + "'";<br>
auto InputOrErr = MemoryBuffer::getFile(Filename);<br>
error(InputOrErr, "error " + CurrentActivity);<br>
InputBuffers.push_back(std::move(*InputOrErr));<br>
<br>
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=307085&r1=307084&r2=307085&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=307085&r1=307084&r2=307085&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)<br>
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Tue Jul 4 08:13:02 2017<br>
@@ -1637,7 +1637,11 @@ static StringRef getBaseRelocTypeName(ui<br>
case COFF::IMAGE_REL_BASED_HIGHADJ: return "HIGHADJ";<br>
case COFF::IMAGE_REL_BASED_ARM_MOV32T: return "ARM_MOV32(T)";<br>
case COFF::IMAGE_REL_BASED_DIR64: return "DIR64";<br>
- default: return "unknown (" + llvm::utostr(Type) + ")";<br>
+ default: {<br>
+ static std::string Result;<br>
+ Result = "unknown (" + llvm::utostr(Type) + ")";<br>
+ return Result;<br></blockquote><div><br>This looks concerning/wrong. Now two callers tot his API could interfere with each other (the returned StringRef is only valid until the function is called again)<br><br>Perhaps this function should return std::string instead.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ }<br>
}<br>
}<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></div></div>