[PATCH] D124524: [demangler] Avoid nullptr UB

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


xbolva00 added a comment.

In D124524#3479827 <https://reviews.llvm.org/D124524#3479827>, @urnathan wrote:

> 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.

Yeah, so SImplifyLibCalls can just drop this restriction and be more aggresive.


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

https://reviews.llvm.org/D124524



More information about the llvm-commits mailing list