[PATCH] D123665: [SimplifyLibCalls] Don't mark memchr() memory as fully dereferenceable

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 02:31:47 PDT 2022


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

C11 specifies memchr() as follows:

> The memchr function locates the first occurrence of c (converted to an unsigned
> char) in the initial n characters (each interpreted as unsigned char ) of the object
> pointed to by s. The implementation shall behave as if it reads the characters sequentially
> and stops as soon as a matching character is found.

In particular, it is well-defined to specify a memchr size larger than the underlying object, as long as the character is found before the end of the object.


https://reviews.llvm.org/D123665

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/mem-deref-bytes.ll
  llvm/test/Transforms/InstCombine/memchr.ll
  llvm/test/Transforms/InstCombine/strchr-1.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123665.422443.patch
Type: text/x-patch
Size: 6557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220413/21c6f8b5/attachment.bin>


More information about the llvm-commits mailing list