[PATCH] D124524: [demangler] Avoid nullptr UB

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 05:37:06 PDT 2022


urnathan added a comment.

In D124524#3479799 <https://reviews.llvm.org/D124524#3479799>, @xbolva00 wrote:

> Can you show some C++ rule why you think that
>
> memcpy(nullptr, nullptr, 0) is UB?
>
> cc @rjmccall
>
> Some time ago I was told this usage is perfectly fine and LLVM cannot assume that dst and src are nonnull pointers.

llvm's sanitizer barfs on such uses.

glibc's header files mark the pointer as non-null:
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,

  size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));

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

It is an unfortunate edge case, but it is what it is.


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

https://reviews.llvm.org/D124524



More information about the llvm-commits mailing list