On Fri, Jul 30, 2021 at 10:53:28AM -0600, Martin Sebor via Gcc wrote:
> On 7/30/21 9:30 AM, Joseph Myers wrote:
> > There are a lot of failures building glibc with mainline GCC right now
> > <https://sourceware.org/pipermail/libc-testresults/2021q3/008335.html>
> > (previously, there were ICEs building glibc on various architectures, so
> > these might be hard to bisect):
> >
> >
> > * x86_64-linux-gnu: "error: array subscript 0 is outside array bounds of
> > '__seg_fs struct pthread * __seg_fs[0]' [-Werror=array-bounds]". This is
> > the one discussed in
> > <https://gcc.gnu.org/pipermail/gcc/2021-July/236922.html>.
>
> I submitted a patch for this warning to Glibc:
> https://sourceware.org/pipermail/libc-alpha/2021-July/128829.html
> which is what ultimately precipitated Florian's question. If null
> pointers to named address spaces are valid I'll adjust GCC to
> avoid the warning for now (as has been discussed, for GCC 12 I'd
> like to redo the logic to detect the problematic null pointer
> arithmetic instead).
They are valid for some address spaces.
See e.g. how gimple.c (check_loadstore) used by
infer_nonnull_range_by_dereference uses a target hook for that:
/* Some address spaces may legitimately dereference zero. */
addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op));
if (targetm.addr_space.zero_address_valid (as))
return false;
Jakub