Skip to content

Commit

Permalink
Make a std::string copy of StringRef Name so that it remains valid wh…
Browse files Browse the repository at this point in the history
…en the original Name is overridden.

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

llvm-svn: 274861
  • Loading branch information
Eric Liu committed Jul 8, 2016
1 parent e1acad9 commit 6ee4e81
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 6ee4e81

Please sign in to comment.