[PATCH] D52933: Fix incorrect Twine usage in CFGPrinter

Jonas Toth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 7 04:22:26 PDT 2018


JonasToth added inline comments.


================
Comment at: include/llvm/Analysis/CFGPrinter.h:176
+    // Evaluate in a single statement to avoid dangling pointers in a Twine.
+    return ("label=\"W:" + Twine(Weight->getZExtValue()) + "\"").str();
   }
----------------
lebedev.ri wrote:
> JonasToth wrote:
> > lebedev.ri wrote:
> > > Reading the http://llvm.org/docs/ProgrammersManual.html#dss-twine, i *do* think the fix is correct.
> > > The old code would call `str()` on a `Twine` stored on a stack,
> > > which is clearly stated as broken in the manual.
> > The pattern for Twine would be `Twine("label=\"W:") + Weight->getZExtValue() + "\"").str()`, why use `Twine` for the second value instead of the first one?
> > The fix itself should still be correct.
> That doesn't compile https://godbolt.org/z/7UhuUJ
Fair point :D


Repository:
  rL LLVM

https://reviews.llvm.org/D52933





More information about the llvm-commits mailing list