Compiling warnings on old GCC

Started by Richard Guoabout 2 years ago4 messages
#1Richard Guo
guofenglinux@gmail.com
1 attachment(s)

I came across the following compiling warnings on GCC (Red Hat 4.8.5-44)
4.8.5 with 'CFLAGS=-Og'

be-fsstubs.c: In function ‘be_lo_export’:
be-fsstubs.c:537:24: warning: ‘fd’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
if (CloseTransientFile(fd) != 0)
^
In file included from trigger.c:14:0:
trigger.c: In function ‘ExecCallTriggerFunc’:
../../../src/include/postgres.h:314:2: warning: ‘result’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
return (Pointer) X;
^
trigger.c:2316:9: note: ‘result’ was declared here
Datum result;
^

I wonder if this is worth fixing, maybe by a trivial patch like
attached.

Thanks
Richard

Attachments:

v1-0001-Silence-old-compiler-about-Wmaybe-uninitialized.patchapplication/octet-stream; name=v1-0001-Silence-old-compiler-about-Wmaybe-uninitialized.patchDownload
From 94ded4bbd852d9ca964e48530ab2af6a3b5a3d43 Mon Sep 17 00:00:00 2001
From: Richard Guo <guofenglinux@gmail.com>
Date: Mon, 6 Nov 2023 14:05:03 +0800
Subject: [PATCH v1] Silence old compiler about -Wmaybe-uninitialized

This patch fixes compiling warnings on GCC (Red Hat 4.8.5-44) 4.8.5 with
'CFLAGS=-Og' about -Wmaybe-uninitialized.
---
 src/backend/commands/trigger.c | 2 +-
 src/backend/libpq/be-fsstubs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 52177759ab..e9f34370b3 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -2313,7 +2313,7 @@ ExecCallTriggerFunc(TriggerData *trigdata,
 {
 	LOCAL_FCINFO(fcinfo, 0);
 	PgStat_FunctionCallUsage fcusage;
-	Datum		result;
+	Datum		result = 0; /* silence old compiler */
 	MemoryContext oldContext;
 
 	/*
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index d189044a4f..a31192edeb 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -482,7 +482,7 @@ be_lo_export(PG_FUNCTION_ARGS)
 {
 	Oid			lobjId = PG_GETARG_OID(0);
 	text	   *filename = PG_GETARG_TEXT_PP(1);
-	int			fd;
+	int			fd = -1; /* silence old compiler */
 	int			nbytes,
 				tmp;
 	char		buf[BUFSIZE];
-- 
2.31.0

#2David Rowley
dgrowleyml@gmail.com
In reply to: Richard Guo (#1)
Re: Compiling warnings on old GCC

On Mon, 6 Nov 2023 at 19:14, Richard Guo <guofenglinux@gmail.com> wrote:

I came across the following compiling warnings on GCC (Red Hat 4.8.5-44)
4.8.5 with 'CFLAGS=-Og'

I wonder if this is worth fixing, maybe by a trivial patch like
attached.

There's some relevant discussion in
/messages/by-id/flat/20220602024243.GJ29853@telsasoft.com

David

#3Richard Guo
guofenglinux@gmail.com
In reply to: David Rowley (#2)
Re: Compiling warnings on old GCC

On Mon, Nov 6, 2023 at 2:51 PM David Rowley <dgrowleyml@gmail.com> wrote:

On Mon, 6 Nov 2023 at 19:14, Richard Guo <guofenglinux@gmail.com> wrote:

I came across the following compiling warnings on GCC (Red Hat 4.8.5-44)
4.8.5 with 'CFLAGS=-Og'

I wonder if this is worth fixing, maybe by a trivial patch like
attached.

There's some relevant discussion in
/messages/by-id/flat/20220602024243.GJ29853@telsasoft.com

Ah, thanks for pointing that out. Somehow I failed to follow that
thread.

It seems that the controversial '-Og' coupled with the old GCC version
(4.8) makes it not worth fixing. So please ignore this thread.

Thanks
Richard

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Richard Guo (#3)
Re: Compiling warnings on old GCC

Richard Guo <guofenglinux@gmail.com> writes:

On Mon, Nov 6, 2023 at 2:51 PM David Rowley <dgrowleyml@gmail.com> wrote:

There's some relevant discussion in
/messages/by-id/flat/20220602024243.GJ29853@telsasoft.com

It seems that the controversial '-Og' coupled with the old GCC version
(4.8) makes it not worth fixing. So please ignore this thread.

Although nobody tried to enunciate a formal policy in the other thread,
I think where we ended up is that we'd consider suppressing warnings
seen with -Og, but only with reasonably-modern compiler versions.
For LTS compilers we are only going to care about warnings seen with
production flags (i.e., -O2 or better).

regards, tom lane