[PATCH] D130494: [InstCombine] Adjust snprintf folding of constant strings (PR #56598)

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 08:54:39 PDT 2022


msebor created this revision.
msebor added reviewers: xbolva00, nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
msebor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The `snprintf` library call handler doesn't consider the POSIX requirement that the function fail and set `errno = EOVERFLOW` when the second argument, `n`, is greater than `INT_MAX`, and folds the subset of such calls to the function with strings of known length to constants.  At the same time the handler only folds these calls if the second argument is greater than the length of the string, and avoids those where it would imply truncation.

This change adjusts the handler to fold all calls with constant strings up to `n == INT_MAX` but not others.  This lets the calls that are required to fail according to POSIX fail on conforming implementations, while letting the folder emit efficient code for the truncating subset of the calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130494

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/snprintf-2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130494.447355.patch
Type: text/x-patch
Size: 12730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/7b4dd283/attachment.bin>


More information about the llvm-commits mailing list