]> granicus.if.org Git - llvm/commitdiff
Make a std::string copy of StringRef Name so that it remains valid when the original...
authorEric Liu <ioeric@google.com>
Fri, 8 Jul 2016 16:09:48 +0000 (16:09 +0000)
committerEric Liu <ioeric@google.com>
Fri, 8 Jul 2016 16:09:48 +0000 (16:09 +0000)
Summary: lib/IR/AutoUpgrade.cpp:348 and lib/IR/AutoUpgrade.cpp:350 upset sanitizer.

Reviewers: bkramer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D22140

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274861 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/AutoUpgrade.cpp

index 7e52bdb36a99a7b7fe074d804b0d2ef81827b9cb..af550eb714637d44afb51007c7087d0fd18d7aee 100644 (file)
@@ -67,7 +67,10 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
   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."