[llvm] r284513 - revert r284495: [Target] remove TargetRecip class

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 15:13:43 PDT 2016


 > I expect you already know, but just in case...

You can generally assume I have no clue. :)

I tried to repro under valgrind on linux, but no luck. Also doesn't repro
for me on macOS in either debug or release.

Is a solution to return a std::string rather than a StringRef because the
string will then be an actual copy rather than a reference?

static std::string getRecipEstimateForFunc(MachineFunction &MF) {
...
  return F->getFnAttribute(RecipAttrName).getValueAsString().str();
}

On Tue, Oct 18, 2016 at 2:51 PM, Tim Northover <t.p.northover at gmail.com>
wrote:

> On 18 October 2016 at 13:48, Tim Northover <t.p.northover at gmail.com>
> wrote:
> > The problem is you're creating (and returning) a StringRef made from a
> > temporary std::string in the function below.
>
> Sorry, scanned through the e-mail too quickly. It's actually
> getRecipEstimateForFunc that matches my descripton:
>
> -static StringRef getRecipEstimateForFunc(MachineFunction &MF) {
> -  const Function *F = MF.getFunction();
> -  StringRef RecipAttrName = "reciprocal-estimates";
> -  if (!F->hasFnAttribute(RecipAttrName))
> -    return StringRef();
> -
> -  return F->getFnAttribute(RecipAttrName).getValueAsString();
> -}
>
> getTargetRecipForFunc also looks sketchy though. I think the
> std::string will be destroyed at the end of the line (techically "full
> expression", but that ends at the semi-colon so whatever).
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161018/b3be3eff/attachment.html>


More information about the llvm-commits mailing list