> On Sep 1, 2021, at 3:35 PM, Iain Sandoe <idsan...@googlemail.com> wrote: > > > [EXTERNAL EMAIL] > > Hi Paul, > >> ... >> If so, then I would think that ignoring it for this patch as well is >> reasonable. If in a given target a pointer that C thinks of as NULL is in >> fact a valid object pointer, then all sorts of optimizations are incorrect. >> If the target really cares, it can use a different representation for the >> null pointer. (Does GCC give us a way to do that?) For example, pdp11 >> could use the all-ones bit pattern to represent an invalid pointer. > > regardless of whether GCC supports it or not - trying to use a non-0 NULL > pointer is likely to break massive amounts of code in the wild. It depends on what you mean by "non-0 NULL pointer". The constant written as 0 in pointer context doesn't represent the all-zeroes bit pattern but rather whatever is a null pointer on that target. Most code would not notice that. The two places I can think of where this would break is (a) if you cast a pointer to int or look at it via a pointer/int union and expect to see integer zero, and (b) if you initialize pointers by using bzero. The former seems rather unlikely, the latter is somewhat common. Can GCC detect the bzero case? It would make a good check for -Wpedantic on the usual platforms that use all zero bits as NULL. > It might, OTOH, be possible to use a non-0 special value to represent the > valid 0 address-use (providing that there is somewhere in the address space > you can steal that from). That would be really ugly, because every pointer reference would have to do the address translation at run time. paul
Re: [PATCH] warn for more impossible null pointer tests
Koning, Paul via Gcc-patches Wed, 01 Sep 2021 13:36:19 -0700
- [PATCH] warn for more impossible null pointe... Martin Sebor via Gcc-patches
- Re: [PATCH] warn for more impossible nu... Jeff Law via Gcc-patches
- Re: [PATCH] warn for more impossibl... Koning, Paul via Gcc-patches
- Re: [PATCH] warn for more impos... Jeff Law via Gcc-patches
- Re: [PATCH] warn for more i... Koning, Paul via Gcc-patches
- Re: [PATCH] warn for m... Iain Sandoe via Gcc-patches
- Re: [PATCH] warn f... Andreas Schwab
- Re: [PATCH] warn f... Koning, Paul via Gcc-patches
- Re: [PATCH] warn for more impossible nu... Jason Merrill via Gcc-patches
- Re: [PATCH] warn for more impossibl... Martin Sebor via Gcc-patches
- Re: [PATCH] warn for more impos... Jason Merrill via Gcc-patches
- Re: [PATCH] warn for more i... Martin Sebor via Gcc-patches
- Re: [PATCH] warn for m... Jason Merrill via Gcc-patches
- Re: [PATCH] warn f... Martin Sebor via Gcc-patches
- Re: [PATCH] wa... Martin Sebor via Gcc-patches
- Re: [PATCH] wa... Jason Merrill via Gcc-patches
- Re: [PATCH] wa... Martin Sebor via Gcc-patches
- Re: [PATCH] wa... Jason Merrill via Gcc-patches