Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:
> Hi, I'm seeing a compiler warning with CFLAGS -O3 but not with -O2.
> In file included from dbcommands.c:20:
> dbcommands.c: In function ‘createdb’:
> ../../../src/include/postgres.h:104:16: warning: ‘src_hasloginevt’ may
> be used uninitialized in this function [-Wmaybe-uninitialized]
Hmm, I also see that at -O3 (not at -O2) when using Fedora 39's
gcc 13.2.1, but *not* when using RHEL8's gcc 8.5.0.
I'm not sure how excited I am about curing that, though, because gcc
13.2.1 spews several other totally baseless warnings (see attached).
Some of them match up with warnings we're seeing on buildfarm member
serinus, which I seem to recall that Andres had tracked to a known gcc
bug.
regards, tom lane
In file included from dbcommands.c:20:
In function 'BoolGetDatum',
inlined from 'createdb' at dbcommands.c:1379:52:
../../../src/include/postgres.h:104:16: warning: 'src_hasloginevt' may be used uninitialized [-Wmaybe-uninitialized]
104 | return (Datum) (X ? 1 : 0);
| ^~~~~~~~~~~~~~~~~~~
dbcommands.c: In function 'createdb':
dbcommands.c:683:25: note: 'src_hasloginevt' was declared here
683 | bool src_hasloginevt;
| ^~~~~~~~~~~~~~~
In file included from ../../../../src/include/executor/instrument.h:16,
from pgstat_io.c:19:
pgstat_io.c: In function 'pgstat_count_io_op_time':
pgstat_io.c:149:60: warning: array subscript 2 is above array bounds of 'instr_time[2][4][8]' [-Warray-bounds=]
149 | INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../../../../src/include/portability/instr_time.h:179:11: note: in definition of macro 'INSTR_TIME_ADD'
179 | ((x).ticks += (y).ticks)
| ^
pgstat_io.c:27:25: note: while referencing 'pending_times'
27 | instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES];
| ^~~~~~~~~~~~~
pgstat_io.c:149:60: warning: array subscript 2 is above array bounds of 'instr_time[2][4][8]' [-Warray-bounds=]
149 | INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../../../../src/include/portability/instr_time.h:179:11: note: in definition of macro 'INSTR_TIME_ADD'
179 | ((x).ticks += (y).ticks)
| ^
pgstat_io.c:27:25: note: while referencing 'pending_times'
27 | instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES];
| ^~~~~~~~~~~~~
pgstat_io.c:149:60: warning: array subscript 2 is above array bounds of 'instr_time[2][4][8]' [-Warray-bounds=]
149 | INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../../../../src/include/portability/instr_time.h:179:11: note: in definition of macro 'INSTR_TIME_ADD'
179 | ((x).ticks += (y).ticks)
| ^
pgstat_io.c:27:25: note: while referencing 'pending_times'
27 | instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES];
| ^~~~~~~~~~~~~
pgstat_io.c:149:60: warning: array subscript 2 is above array bounds of 'instr_time[2][4][8]' [-Warray-bounds=]
149 | INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../../../../src/include/portability/instr_time.h:179:11: note: in definition of macro 'INSTR_TIME_ADD'
179 | ((x).ticks += (y).ticks)
| ^
pgstat_io.c:27:25: note: while referencing 'pending_times'
27 | instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES];
| ^~~~~~~~~~~~~
In file included from ../../../../src/include/access/htup_details.h:22,
from pl_exec.c:21:
In function 'assign_simple_var',
inlined from 'exec_set_found' at pl_exec.c:8349: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)))
| ^~~~~~~~~~~~~~~
pl_exec.c:8537:17: note: in expansion of macro 'VARATT_IS_EXTERNAL_NON_EXPANDED'
8537 | VARATT_IS_EXTERNAL_NON_EXPANDED(DatumGetPointer(newvalue)))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'exec_set_found':
cc1: note: source object is likely at address zero