From: Dmitry Mityugov <d.mityugov@postgrespro.ru>
To: pgsql-hackers@postgresql.org
Subject: patch: Use pg_assume in jsonb_util.c to fix GCC 15 warnings
Date: Thu, 10 Jul 2025 23:00:00 +0300
Message-ID: <0c623e8a204187b87b4736792398eaf1@postgrespro.ru> (raw)
When compiled with Assert() macro disabled, GCC 15 produces warnings
about possibly uninitialized variables in
src/backend/utils/adt/jsonb_util.c module. This problem was discussed in
detail in this thread, in April 2025:
https://www.postgresql.org/message-id/988bf1bc-3f1f-99f3-bf98-222f1cd9dc5e@xs4all.nl
.
Recently introduced pg_assume() macro let fix such problems easily. The
attached patch fixes them in jsonb_util.c module. I verified that
PostgreSQL compiles clearly with this patch and GCC 15.1.1 on an x86
64-bit machine (with and without --enable-cassert), and with GCC 14.2.1
on a 64-bit ARM machine. `make check` also passes.
I'm attaching the patch.
Regards,
Dmitry
Attachments:0001-Use-pg_assume-in-jsonb_util.c-to-fix-GCC-15-warning.patch (text/x-diff, 1.1K) download
From: Dmitry Mityugov <d.mityugov@postgrespro.ru>
Date: Thu, 10 Jul 2025 22:05:12 +0300
Subject: Use pg_assume in jsonb_util.c to fix GCC 15 warnings
Recently introduced pg_assume macro is a great tool to silence GCC 15 warnings
generated for release builds, when Assert() macro is disabled. This patch fixes
two of them in backend/utils/adt/jsonb_util.c module.
---
src/backend/utils/adt/jsonb_util.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.cindex c18bf741521..2478346ce19 100644--- a/src/backend/utils/adt/jsonb_util.c+++ b/src/backend/utils/adt/jsonb_util.c@@ -291,8 +291,8 @@ compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)
* WJB_BEGIN_ARRAY and WJB_BEGIN_OBJECT tokens first, and
* concluded that they don't match.
*/
- Assert(ra != WJB_END_ARRAY && ra != WJB_END_OBJECT);- Assert(rb != WJB_END_ARRAY && rb != WJB_END_OBJECT);+ pg_assume(ra != WJB_END_ARRAY && ra != WJB_END_OBJECT);+ pg_assume(rb != WJB_END_ARRAY && rb != WJB_END_OBJECT);
Assert(va.type != vb.type);
Assert(va.type != jbvBinary);
--
2.50.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: d.mityugov@postgrespro.ru
Subject: Re: patch: Use pg_assume in jsonb_util.c to fix GCC 15 warnings
In-Reply-To: <0c623e8a204187b87b4736792398eaf1@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox