[PATCH] D22140: Make a std::string copy of StringRef Name so that it remains valid when the original Name is overridden.

Eric Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 08:57:56 PDT 2016


ioeric created this revision.
ioeric added a reviewer: bkramer.
ioeric added a subscriber: llvm-commits.

lib/IR/AutoUpgrade.cpp:348 and lib/IR/AutoUpgrade.cpp:350 upset sanitizer.

http://reviews.llvm.org/D22140

Files:
  lib/IR/AutoUpgrade.cpp

Index: lib/IR/AutoUpgrade.cpp
===================================================================
--- lib/IR/AutoUpgrade.cpp
+++ 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.63236.patch
Type: text/x-patch
Size: 618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/d3aedc4d/attachment.bin>


More information about the llvm-commits mailing list