[all-commits] [llvm/llvm-project] 8c7416: [SimplifyLibCalls] Don't mark memchr() memory as f...

Nikita Popov via All-commits all-commits at lists.llvm.org
Wed Apr 13 07:46:34 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8c74169990c0b179fa9a0c82f8d6ca35889b9ec4
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2022-04-13 (Wed, 13 Apr 2022)

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

  Log Message:
  [SimplifyLibCalls] Don't mark memchr() memory as fully dereferenceable

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.

Differential Revision: https://reviews.llvm.org/D123665

More information about the All-commits mailing list