[Bug c++/105864] storing nullptr_t to memory should not generate any instructions

vanyacpp at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jun 21 08:09:43 GMT 2022


--- Comment #5 from Ivan Sorokin <vanyacpp at gmail dot com> ---
I would suggest (In reply to Andrew Pinski from comment #4)
>   nullptr_t t, t1 = nullptr;
>   __builtin_memcpy(&a[0], &t, sizeof(t));

> So I suspect this should be marked as invalid.

The questions is how GCC defines memcpy'ing from nullptr_t.

Should it be required to read zero bytes? Or null pointer value? What about
systems where the value of null pointer is not zero?

In any case I don't think memcpy'ing nullptr_t into a different type is
particularly useful or used anywhere (I might be wrong). So I suggest defining
nullptr_t as an empty type containing only padding bytes. In this case memcpy
should just read the padding bytes.

More information about the Gcc-bugs mailing list