| From: | "Tristan Partin" <tristan(at)partin(dot)io> |
|---|---|
| To: | "Andres Freund" <andres(at)anarazel(dot)de> |
| Cc: | <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Subject: | Re: gcc 15 "array subscript 0" warning at level -O3 |
| Date: | 2026-10-16 10:02:53 |
| Message-ID: | DM66DF3UKYTH.36WEM0YK0YUT5@partin.io |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed Jul 9, 2025 at 11:20 PM UTC, Andres Freund wrote:
> Hi,
>
> On 2025-06-05 15:50:48 -0400, Tom Lane wrote:
>> Andres Freund <andres(at)anarazel(dot)de> writes:
>> >> 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.
>>
>> Looks plausible by eyeball. I did notice a typo in the comment:
>>
>> + * pg_assume(expr) stats that we assume `expr` to evaluate to true. In assert
>>
>> s/stats/states/, I think you meant.
>
> Thanks. I pushed it with that tweak and a bit of minor comment burnishing.
> Glad to see the last of that warning.
Was this supposed to be backpatched? I was able to reproduce the warning
for GCC 16.2.0 on Amazon Linux 2023 using the REL_18_STABLE branch using
a release buildtype via Meson.
$ gcc --version
gcc (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
...
[1475/2276] Compiling C object src/pl/plpgsql/src/plpgsql.so.p/pl_exec.c.o
In file included from ../src/include/access/htup_details.h:22,
from ../src/pl/plpgsql/src/pl_exec.c:21:
In function ‘assign_simple_var’,
inlined from ‘exec_set_found’ at ../src/pl/plpgsql/src/pl_exec.c:8607:2:
../src/include/varatt.h:230:36: warning: array subscript 0 is outside array bounds of ‘char[0]’ [-Warray-bounds=]
230 | (((varattrib_1b_e *) (PTR))->va_tag)
| ^
../src/include/varatt.h:94:12: note: in definition of macro ‘VARTAG_IS_EXPANDED’
94 | (((tag) & ~1) == VARTAG_EXPANDED_RO)
| ^~~
../src/include/varatt.h:284:57: note: in expansion of macro ‘VARTAG_1B_E’
284 | #define VARTAG_EXTERNAL(PTR) VARTAG_1B_E(PTR)
| ^~~~~~~~~~~
../src/include/varatt.h:301:57: note: in expansion of macro ‘VARTAG_EXTERNAL’
301 | (VARATT_IS_EXTERNAL(PTR) && !VARTAG_IS_EXPANDED(VARTAG_EXTERNAL(PTR)))
| ^~~~~~~~~~~~~~~
../src/pl/plpgsql/src/pl_exec.c:8795:17: note: in expansion of macro ‘VARATT_IS_EXTERNAL_NON_EXPANDED’
8795 | VARATT_IS_EXTERNAL_NON_EXPANDED(DatumGetPointer(newvalue)))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My REL_18_STABLE branch HEAD is
707b3738df95541a9f1d93f2c9a3b96e3f8416d5.
--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Matthias van de Meent | 2026-10-16 10:01:43 | Re: UNDO with constant time recovery (CTR) |