Re: Silence -Wmaybe-uninitialized warnings - Mailing list pgsql-hackers

From Bertrand Drouvot
Subject Re: Silence -Wmaybe-uninitialized warnings
Date
Msg-id ac/S+OxBlPPAZaub@ip-10-97-1-34.eu-west-3.compute.internal
Whole thread Raw
In response to Re: Silence -Wmaybe-uninitialized warnings  (Imran Zaheer <imran.zhir@gmail.com>)
List pgsql-hackers
Hi,

On Fri, Apr 03, 2026 at 07:14:18PM +0500, Imran Zaheer wrote:
> Hi
> 
> I pulled the latest HEAD today and found some more -Wmaybe-uninitialized
> warnings.
> 
> ```
> [1/6] Compiling C object
> src/interfaces/ecpg/test/pg_regress_ecpg.p/.._.._.._test_regress_pg_regress.c.o
> ../src/test/regress/pg_regress.c: In function ‘results_differ’:
> ../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>  1577 |                 fseek(difffile, startpos, SEEK_SET);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> [2/6] Compiling C object
> src/test/isolation/pg_isolation_regress.p/.._regress_pg_regress.c.o
> ../src/test/regress/pg_regress.c: In function ‘results_differ’:
> ../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>  1577 |                 fseek(difffile, startpos, SEEK_SET);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> [3/6] Compiling C object src/test/regress/pg_regress.p/pg_regress.c.o
> ../src/test/regress/pg_regress.c: In function ‘results_differ’:
> ../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>  1577 |                 fseek(difffile, startpos, SEEK_SET);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ```
> 
> Here is the updated v2 patch addressing them.

That's an "old" compiler hallucination.

With an "old" one:

$ gcc -Isrc/backend/postgres_lib.a.p -Isrc/include -I../src/include \
     -Og -fPIC -pthread -DBUILDING_DLL -Wmaybe-uninitialized \
     -o src/backend/postgres_lib.a.p/partitioning_partbounds.c.o \
     -c ../src/backend/partitioning/partbounds.c
../src/backend/partitioning/partbounds.c: In function ‘check_partition_bounds_for_split_range’:
../src/backend/partitioning/partbounds.c:5452:57: warning: ‘datum’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
 5452 |                                                         parser_errposition(pstate, exprLocation((Node *)
datum)));

$ gcc --version
gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)

I can see the same warning that you reported.

But with a more recent one:

/usr/bin/gcc14-gcc -Isrc/backend/postgres_lib.a.p -Isrc/include -I../src/include \
     -Og -fPIC -pthread -DBUILDING_DLL -Wmaybe-uninitialized \
     -o src/backend/postgres_lib.a.p/partitioning_partbounds.c.o \
     -c ../src/backend/partitioning/partbounds.c

There are no warnings.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: pg_waldump: support decoding of WAL inside tarfile
Next
From: Bertrand Drouvot
Date:
Subject: meson: Adjust test timeout for Valgrind builds