Re: gcc 15 "array subscript 0" warning at level -O3
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2025-07-02T14:13:17Z
Lists: 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/
Commits
-
Use pg_assume() to avoid compiler warning below exec_set_found()
- 48a23f6eae71 19 (unreleased) landed
-
Add pg_assume(expr) macro
- d65eb5b1b84e 19 (unreleased) landed