[PATCH] D22140: Move setName after accessing Name.

Eric Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 09:17:05 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL274861: Make a std::string copy of StringRef Name so that it remains valid when theā€¦ (authored by ioeric).

Changed prior to commit:
  http://reviews.llvm.org/D22140?vs=63243&id=63244#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22140

Files:
  llvm/trunk/lib/IR/AutoUpgrade.cpp

Index: llvm/trunk/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/trunk/lib/IR/AutoUpgrade.cpp
+++ llvm/trunk/lib/IR/AutoUpgrade.cpp
@@ -67,7 +67,10 @@
   assert(F && "Illegal to upgrade a non-existent Function.");
 
   // Quickly eliminate it, if it's not a candidate.
-  StringRef Name = F->getName();
+  // Make a copy of the name so that we don't need to worry about the life-time
+  // of StringRef.
+  std::string NameStr = F->getName().str();
+  StringRef Name = NameStr;
   if (Name.size() <= 8 || !Name.startswith("llvm."))
     return false;
   Name = Name.substr(5); // Strip off "llvm."


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22140.63244.patch
Type: text/x-patch
Size: 651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/898ef966/attachment.bin>


More information about the llvm-commits mailing list