[PATCH] D124633: [SimplifyLibCalls] Pointers passed to libcalls must point to valid objects

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 12:39:16 PDT 2022


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

> c99: 7.21.2.1 "The memcpy function copies n characters from the object pointed to by s2 into the
> object pointed to by s1. If copying takes place between objects that overlap, the behavior
> is undefined."

**null is not a pointer to an object**

So even when size is zero, pointer(s) must be valid.

If this rule is broken, UBSan catches this UB without any problems, as recently shown in: https://reviews.llvm.org/D124524 / https://godbolt.org/z/qx4sK43f6


https://reviews.llvm.org/D124633

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/bcmp-1.ll
  llvm/test/Transforms/InstCombine/bcopy.ll
  llvm/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
  llvm/test/Transforms/InstCombine/mem-deref-bytes.ll
  llvm/test/Transforms/InstCombine/memcmp-1.ll
  llvm/test/Transforms/InstCombine/memcpy-1.ll
  llvm/test/Transforms/InstCombine/memcpy-2.ll
  llvm/test/Transforms/InstCombine/memmove-1.ll
  llvm/test/Transforms/InstCombine/memmove.ll
  llvm/test/Transforms/InstCombine/mempcpy.ll
  llvm/test/Transforms/InstCombine/memrchr-3.ll
  llvm/test/Transforms/InstCombine/memset-1.ll
  llvm/test/Transforms/InstCombine/memset_chk-1.ll
  llvm/test/Transforms/InstCombine/sprintf-1.ll
  llvm/test/Transforms/PhaseOrdering/ARM/arm_fill_q7.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124633.425880.patch
Type: text/x-patch
Size: 39144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220428/ae676092/attachment.bin>


More information about the llvm-commits mailing list