Compile warnings in dbcommands.c building with meson

Started by Magnus Haganderabout 2 years ago7 messages
#1Magnus Hagander
magnus@hagander.net

When building current head on debian bullseye I get this compile warning:

In file included from ../src/backend/commands/dbcommands.c:20:
../src/backend/commands/dbcommands.c: In function ‘createdb’:
../src/include/postgres.h:104:9: warning: ‘src_hasloginevt’ may be
used uninitialized in this function [-Wmaybe-uninitialized]
104 | return (Datum) (X ? 1 : 0);
| ^~~~~~~~~~~~~~~~~~~
../src/backend/commands/dbcommands.c:683:8: note: ‘src_hasloginevt’
was declared here
683 | bool src_hasloginevt;
| ^~~~~~~~~~~~~~~

I only get this when building with meson, not when building with
autotools. AFAICT, I have the same config:

./configure --enable-debug --enable-depend --with-python
--enable-cassert --with-openssl --enable-tap-tests --with-icu

vs

meson setup build -Ddebug=true -Dpython=true -Dcassert=true
-Dssl=openssl -Dtap-test=true -Dicu=enabled -Dnls=disabled

in both cases the compiler is:
gcc (Debian 10.2.1-6) 10.2.1 20210110

--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/

#2Aleksander Alekseev
aleksander@timescale.com
In reply to: Magnus Hagander (#1)
1 attachment(s)
Re: Compile warnings in dbcommands.c building with meson

Hi,

When building current head on debian bullseye I get this compile warning:

In file included from ../src/backend/commands/dbcommands.c:20:
../src/backend/commands/dbcommands.c: In function ‘createdb’:
../src/include/postgres.h:104:9: warning: ‘src_hasloginevt’ may be
used uninitialized in this function [-Wmaybe-uninitialized]
104 | return (Datum) (X ? 1 : 0);
| ^~~~~~~~~~~~~~~~~~~
../src/backend/commands/dbcommands.c:683:8: note: ‘src_hasloginevt’
was declared here
683 | bool src_hasloginevt;
| ^~~~~~~~~~~~~~~

I only get this when building with meson, not when building with
autotools. AFAICT, I have the same config:

./configure --enable-debug --enable-depend --with-python
--enable-cassert --with-openssl --enable-tap-tests --with-icu

vs

meson setup build -Ddebug=true -Dpython=true -Dcassert=true
-Dssl=openssl -Dtap-test=true -Dicu=enabled -Dnls=disabled

in both cases the compiler is:
gcc (Debian 10.2.1-6) 10.2.1 20210110

Seems to me that the compiler is not smart enough to process:

```
if (!get_db_info(dbtemplate, ShareLock,
&src_dboid, &src_owner, &src_encoding,
&src_istemplate, &src_allowconn, &src_hasloginevt,
&src_frozenxid, &src_minmxid, &src_deftablespace,
&src_collate, &src_ctype, &src_iculocale,
&src_icurules, &src_locprovider,
&src_collversion))
ereport(ERROR, ...
```

Should we just silence the warning like this - see attachment? I don't
think createdb() is called that often to worry about slight
performance change, if there is any.

--
Best regards,
Aleksander Alekseev

Attachments:

v1-0001-Silence-compiler-warnings.patchapplication/octet-stream; name=v1-0001-Silence-compiler-warnings.patchDownload
From 098a99d1b9bc67a8ef4c4004bb8c081e87b94f38 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Wed, 10 Jan 2024 15:14:11 +0300
Subject: [PATCH v1] Silence compiler warnings

---
 src/backend/commands/dbcommands.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 0a97a11314..6cbdd5b360 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -679,12 +679,12 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
 	char	   *src_icurules = NULL;
 	char		src_locprovider = '\0';
 	char	   *src_collversion = NULL;
-	bool		src_istemplate;
-	bool		src_hasloginevt;
-	bool		src_allowconn;
+	bool		src_istemplate = false;
+	bool		src_hasloginevt = false;
+	bool		src_allowconn = false;
 	TransactionId src_frozenxid = InvalidTransactionId;
 	MultiXactId src_minmxid = InvalidMultiXactId;
-	Oid			src_deftablespace;
+	Oid			src_deftablespace = InvalidOid;
 	volatile Oid dst_deftablespace;
 	Relation	pg_database_rel;
 	HeapTuple	tuple;
-- 
2.43.0

#3Magnus Hagander
magnus@hagander.net
In reply to: Aleksander Alekseev (#2)
Re: Compile warnings in dbcommands.c building with meson

On Wed, Jan 10, 2024 at 1:16 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi,

When building current head on debian bullseye I get this compile warning:

In file included from ../src/backend/commands/dbcommands.c:20:
../src/backend/commands/dbcommands.c: In function ‘createdb’:
../src/include/postgres.h:104:9: warning: ‘src_hasloginevt’ may be
used uninitialized in this function [-Wmaybe-uninitialized]
104 | return (Datum) (X ? 1 : 0);
| ^~~~~~~~~~~~~~~~~~~
../src/backend/commands/dbcommands.c:683:8: note: ‘src_hasloginevt’
was declared here
683 | bool src_hasloginevt;
| ^~~~~~~~~~~~~~~

I only get this when building with meson, not when building with
autotools. AFAICT, I have the same config:

./configure --enable-debug --enable-depend --with-python
--enable-cassert --with-openssl --enable-tap-tests --with-icu

vs

meson setup build -Ddebug=true -Dpython=true -Dcassert=true
-Dssl=openssl -Dtap-test=true -Dicu=enabled -Dnls=disabled

in both cases the compiler is:
gcc (Debian 10.2.1-6) 10.2.1 20210110

Seems to me that the compiler is not smart enough to process:

```
if (!get_db_info(dbtemplate, ShareLock,
&src_dboid, &src_owner, &src_encoding,
&src_istemplate, &src_allowconn, &src_hasloginevt,
&src_frozenxid, &src_minmxid, &src_deftablespace,
&src_collate, &src_ctype, &src_iculocale,
&src_icurules, &src_locprovider,
&src_collversion))
ereport(ERROR, ...
```

Should we just silence the warning like this - see attachment? I don't
think createdb() is called that often to worry about slight
performance change, if there is any.

Certainly looks that way, but I'm curious as to why nobody else has seen this..

That said, it appears to be gone in current master. Even though
nothing changed in that file. Must've been some transient effect,
that somehow didn't get blown away by doing a clean....

--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/

#4jian he
jian.universality@gmail.com
In reply to: Magnus Hagander (#3)
Re: Compile warnings in dbcommands.c building with meson

On Fri, Jan 12, 2024 at 1:05 AM Magnus Hagander <magnus@hagander.net> wrote:

On Wed, Jan 10, 2024 at 1:16 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi,

When building current head on debian bullseye I get this compile warning:

In file included from ../src/backend/commands/dbcommands.c:20:
../src/backend/commands/dbcommands.c: In function ‘createdb’:
../src/include/postgres.h:104:9: warning: ‘src_hasloginevt’ may be
used uninitialized in this function [-Wmaybe-uninitialized]
104 | return (Datum) (X ? 1 : 0);
| ^~~~~~~~~~~~~~~~~~~
../src/backend/commands/dbcommands.c:683:8: note: ‘src_hasloginevt’
was declared here
683 | bool src_hasloginevt;
| ^~~~~~~~~~~~~~~

I only get this when building with meson, not when building with
autotools. AFAICT, I have the same config:

./configure --enable-debug --enable-depend --with-python
--enable-cassert --with-openssl --enable-tap-tests --with-icu

vs

meson setup build -Ddebug=true -Dpython=true -Dcassert=true
-Dssl=openssl -Dtap-test=true -Dicu=enabled -Dnls=disabled

in both cases the compiler is:
gcc (Debian 10.2.1-6) 10.2.1 20210110

Seems to me that the compiler is not smart enough to process:

```
if (!get_db_info(dbtemplate, ShareLock,
&src_dboid, &src_owner, &src_encoding,
&src_istemplate, &src_allowconn, &src_hasloginevt,
&src_frozenxid, &src_minmxid, &src_deftablespace,
&src_collate, &src_ctype, &src_iculocale,
&src_icurules, &src_locprovider,
&src_collversion))
ereport(ERROR, ...
```

Should we just silence the warning like this - see attachment? I don't
think createdb() is called that often to worry about slight
performance change, if there is any.

Certainly looks that way, but I'm curious as to why nobody else has seen this..

I saw it sometimes, sometimes not.
Now I think the reason is:
it will appear when you do `-Dbuildtype=release`.

but it will not occur when I do:
`-Dbuildtype=debug`

my current meson version is 1.3.1, my ninja version is 1.10.1.

#5Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: jian he (#4)
Re: Compile warnings in dbcommands.c building with meson

On 2024-Jan-12, jian he wrote:

I saw it sometimes, sometimes not.
Now I think the reason is:
it will appear when you do `-Dbuildtype=release`.

but it will not occur when I do:
`-Dbuildtype=debug`

my current meson version is 1.3.1, my ninja version is 1.10.1.

Hmm, but why doesn't it happen for other arguments of get_db_info that
have pretty much identical code, say src_istemplate?

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"But static content is just dynamic content that isn't moving!"
http://smylers.hates-software.com/2007/08/15/fe244d0c.html

#6jian he
jian.universality@gmail.com
In reply to: Alvaro Herrera (#5)
Re: Compile warnings in dbcommands.c building with meson

On Fri, Jan 12, 2024 at 8:03 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

On 2024-Jan-12, jian he wrote:

I saw it sometimes, sometimes not.
Now I think the reason is:
it will appear when you do `-Dbuildtype=release`.

but it will not occur when I do:
`-Dbuildtype=debug`

my current meson version is 1.3.1, my ninja version is 1.10.1.

Hmm, but why doesn't it happen for other arguments of get_db_info that
have pretty much identical code, say src_istemplate?

git at commit 6780b79d5c580586ae6feb37b9c8b8bf33367886 (HEAD ->
master, origin/master, origin/HEAD)
the minimum setup that will generate the warning:

meson setup --reconfigure ${BUILD} \
-Dprefix=${PG_PREFIX} \
-Dpgport=5462 \
-Dbuildtype=release

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 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.

#7jian he
jian.universality@gmail.com
In reply to: Aleksander Alekseev (#2)
Re: Compile warnings in dbcommands.c building with meson

Hi. one more feedback.

I tested the original repo setup, but it does not generate a warning
on my local setup.
meson setup --reconfigure ${BUILD} \
-Dprefix=${PG_PREFIX} \
-Dpgport=5463 \
-Dplpython=enabled \
-Dcassert=true \
-Dtap_tests=enabled \
-Dicu=enabled \
-Ddebug=true \
-Dnls=disabled

it generate warning, when I add -Dbuildtype=release :

meson setup --reconfigure ${BUILD} \
-Dprefix=${PG_PREFIX} \
-Dpgport=5463 \
-Dplpython=enabled \
-Dcassert=true \
-Dtap_tests=enabled \
-Dicu=enabled \
-Dbuildtype=release \
-Ddebug=true \
-Dnls=disabled

After applying the patch, the warning disappeared.
so it fixed the problem.