Re: gcc 15 "array subscript 0" warning at level -O3 - Mailing list pgsql-hackers

From jian he
Subject Re: gcc 15 "array subscript 0" warning at level -O3
Date
Msg-id CACJufxFZ5Bb93=c0aQ+u4b94auYcOdhRnNQHkV7ASpTX1uzW+A@mail.gmail.com
Whole thread Raw
In response to Re: gcc 15 "array subscript 0" warning at level -O3  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Thu, Jun 5, 2025 at 3:00 AM Andres Freund <andres@anarazel.de> wrote:
>
> > > The dereference is not reachable
> > > because of the preceding "var->datatype->typlen == -1" check,
> > > but that's not stopping the optimizer from bitching.
> >
> > > I experimented with modifying exec_set_found thus:
> > >
> > >     var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
> > > +   Assert(var->datatype->typlen == 1);
> > >     assign_simple_var(estate, var, BoolGetDatum(state), false, false);
> > >
> > > which should be OK since we're expecting the "found" variable to
> > > be boolean.  That does silence the warning, but of course only
> > > in --enable-cassert builds.
> >
> > One way to address this is outlined here:
> >
> > https://postgr.es/m/20230316172818.x6375uvheom3ibt2%40awork3.anarazel.de
> > https://postgr.es/m/20240207203138.sknifhlppdtgtxnk%40awork3.anarazel.de
> >
> > I've been wondering about adding wrapping something like that in a
> > pg_assume(expr) or such.
>
> I've been once more annoyed by this warning. Here's a prototype for the
> approach outlined above.
>

I can confirm the warning disappears when using gcc-14.0 compile
source code with the attached patch.
I didn't review it though.
I didn’t find this in the CommitFest, so I added an entry [1] to make sure it
doesn’t get forgotten...

[1]: https://commitfest.postgresql.org/patch/5888/



pgsql-hackers by date:

Previous
From: Dagfinn Ilmari Mannsåker
Date:
Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username
Next
From: Fujii Masao
Date:
Subject: Re: Add progressive backoff to XactLockTableWait functions