[Bug c++/97976] Optimization relating to NULL pointer assumptions in gcc 9.1

peter at int19h dot net gcc-bugzilla@gcc.gnu.org
Thu Nov 26 01:37:40 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97976

--- Comment #10 from Peter Bisroev <peter at int19h dot net> ---
Jonathan, thank you so much for your explanation. As soon as I read it, it all
started to make sense.

>You cannot increment or decrement a pointer past the end of an array (except the one past the end position).

Yes of course, that is perfectly reasonable. And unless I am mistaken, the
examples that I have provided do not do that directly because as the "array" in
those examples starts at address 0 as can be possible in some embedded systems.
But with the knowledge about how by default gcc treats a pointer to address 0
everything can be perfectly explained.

>GCC assumes there is no object at address zero, see the documentation for -fdelete-null-pointer-checks

Thank you for pointing this flag out to me. After reading its description and
searching a bit I can see that I am not the only one that got caught off guard
with this as shown in these links:

* https://gcc.gnu.org/legacy-ml/gcc-patches/2015-04/msg00790.html
* https://gcc.gnu.org/legacy-ml/gcc-patches/2007-03/msg01968.html
* https://lkml.org/lkml/2018/4/4/601
* https://reviews.llvm.org/D47894

I will definitely go through gcc man page again to see if there is anything
else that we should pay attention to.

Once again, thank you for taking the time to explain all of this!


More information about the Gcc-bugs mailing list