compiler warnings with gcc 4.8 and -Og

Поиск
Список
Период
Сортировка
От Justin Pryzby
Тема compiler warnings with gcc 4.8 and -Og
Дата
Msg-id 20220602024243.GJ29853@telsasoft.com
обсуждение исходный текст
Ответы Re: compiler warnings with gcc 4.8 and -Og  (Michael Paquier <michael@paquier.xyz>)
Re: compiler warnings with gcc 4.8 and -Og  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
forking: <20220302205058.GJ15744@telsasoft.com>: Re: Adding CI to our tree

On Wed, Mar 02, 2022 at 02:50:58PM -0600, Justin Pryzby wrote:
> BTW (regarding the last patch), I just noticed that -Og optimization can cause
> warnings with gcc-4.8.5-39.el7.x86_64.
> 
> be-fsstubs.c: In function 'be_lo_export':
> be-fsstubs.c:522:24: warning: 'fd' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   if (CloseTransientFile(fd) != 0)
>                         ^
> trigger.c: In function 'ExecCallTriggerFunc':
> trigger.c:2400:2: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   return (HeapTuple) DatumGetPointer(result);
>   ^
> xml.c: In function 'xml_pstrdup_and_free':
> xml.c:1205:2: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   return result;

Today's "warnings" thread suggests to me that these are worth fixing - it seems
reasonable to compile postgres 14 on centos7 (as I sometimes have done), and
the patch seems even more reasonable when backpatched to older versions.
(Also, I wonder if there's any consideration to backpatch cirrus.yaml, which
uses -Og)

The buildfarm has old GCC, but they all use -O2, so the warnings are not seen
there.

The patch below applies and fixes warnings back to v13.

In v13, pl_handler.c has another warning, which suggests to backpatch
7292fd8f1.

In v12, there's a disparate separate set of warnings which could be dealt with
separately.

v9.3-v11 have no warnings on c7 with -Og.

Thomas mentioned [0] that cfbot's linux (which is using gcc 10) gives other
warnings since using -Og, which (in addition to being unpleasant to look at) is
hard to accept, seeing as there's a whole separate task just for
"CompilerWarnings"...  But I don't know what to do about those.

[0] https://www.postgresql.org/message-id/CA+hUKGK1cF+TMW1cyoujoDAX5FBdoA59C--1HT7yCQGBbq1ddQ@mail.gmail.com

diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 40441fdb4c..bb64de2843 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -2105,7 +2105,7 @@ ExecCallTriggerFunc(TriggerData *trigdata,
 {
     LOCAL_FCINFO(fcinfo, 0);
     PgStat_FunctionCallUsage fcusage;
-    Datum        result;
+    Datum        result = 0;
     MemoryContext oldContext;
 
     /*
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 63eaccc80a..3e2c094e1e 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -467,7 +467,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;
     int            nbytes,
                 tmp;
     char        buf[BUFSIZE];
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index f90a9424d4..7ffbae5a09 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -1185,7 +1185,7 @@ pg_xmlCharStrndup(const char *str, size_t len)
 static char *
 xml_pstrdup_and_free(xmlChar *str)
 {
-    char       *result;
+    char       *result = NULL;
 
     if (str)
     {
@@ -1199,8 +1199,6 @@ xml_pstrdup_and_free(xmlChar *str)
         }
         PG_END_TRY();
     }
-    else
-        result = NULL;
 
     return result;
 }



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: [PATCH] Fix pg_upgrade test from v10
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: compiler warnings with gcc 4.8 and -Og