[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 09:56:51 PDT 2019


xbolva00 marked 2 inline comments as done.
xbolva00 added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:2581
+              B.CreateSub(SizeArg, ConstantInt::get(SizeArg->getType(), 1));
+          emitMemCCpy(Dst, CI->getArgOperand(3), B.getInt32('\0'), DecSize, B,
+                      TLI);
----------------
lebedev.ri wrote:
> Where did we ask TLI about the existence of `memccpy`?
emitMemCCpy calls emitLibcall which checks it - otherwise returns nullptr. 

Ah, and we should not emit store in that case, if emitmemccpy failed. Thanks!


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:2583
+                      TLI);
+          Value *DstEnd = B.CreateGEP(B.getInt8Ty(), Dst, DecSize);
+          B.CreateStore(B.getInt8(0), DstEnd);
----------------
lebedev.ri wrote:
> It likely should be `CreateInBoundsGEP()`.
I was wondering about this too, then code above is broken too :) I will fix it.


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

https://reviews.llvm.org/D67986





More information about the llvm-commits mailing list