[PATCH] D67986: [InstCombine] snprintf (d, size, "%s", s) -> memccpy (d, s, '\0', size - 1), d[size - 1] = 0

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 15:59:55 PDT 2019


xbolva00 abandoned this revision.
xbolva00 added a comment.

In D67986#1692126 <https://reviews.llvm.org/D67986#1692126>, @efriedma wrote:

> You could do something like `if (!memccpy (d, s, '\0', size - 1)) d[size - 1] = 0;`, I guess.  That's a few more instructions that I'd really like, but I don't see a better alternative.


Yeah, but probably InstCombine is not best place to create such ranches/phis, select would be better.

Maybe this could work?
char *ret = memccpy (d, s, '\0', n - 1);
char * ptr = ret ? ret - 1 :  &d[n - 1];
*ptr = 0;


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67986/new/

https://reviews.llvm.org/D67986





More information about the llvm-commits mailing list