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-222f1cd9d...@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
From: Dmitry Mityugov <d.mityu...@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.c
index 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