Hi Paul,

Regarding these two warnings:

 * -O1, -O2, -O3, -Og, -Os only:
 ../../gllib/getndelim2.c:191:23: warning: 'c' may be used uninitialized 
[-Wmaybe-uninitialized]
 
 * -O2, -O3 only:
 ../../gllib/canonicalize.c:385:33: warning: 'end_idx' may be used 
uninitialized [-Wmaybe-uninitialized]

I'm seeing these warnings, although an IF_LINT invocation is meant to suppress
them.

Some time ago, a distro guy explained on this list that IF_LINT does not
help in their situation, because the distro wants to build each package
once, with the settings that produce the best code, _and_ have the compiler
report warnings for this situation.

I'm in a similar situation: When I compile gnulib testdirs or gettext, I
don't want to have two different ways to compile it: once for getting
the warnings and once for getting the binaries, that I then run through
"make check" (optionally with valgrind).

So the IF_LINT mechanism does not work well for me either.

How about the following patches? They replace two uses of IF_LINT with
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized".
The loss for reliability is small: it silences the "maybe uninitialized"
findings for an entire function, instead of just for one variable.
The upside is that it removes the warning on glibc systems and thereby
helps the human developer (me) focusing on real warnings produced by gcc.

Is that OK with you, or do you have objections?

Bruno

>From df699049f9378d03cd7ecfff32873d1557baf790 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:42:00 +0200
Subject: [PATCH 1/2] canonicalize: Silence gcc warning.

* lib/canonicalize.c: Add #pragma GCC diagnostic.
(IF_LINT): Remove macro.
(canonicalize_filename_mode_stk): Remove use of IF_LINT.
---
 ChangeLog          |  7 +++++++
 lib/canonicalize.c | 14 ++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 50a9cef230..717789d423 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	canonicalize: Silence gcc warning.
+	* lib/canonicalize.c: Add #pragma GCC diagnostic.
+	(IF_LINT): Remove macro.
+	(canonicalize_filename_mode_stk): Remove use of IF_LINT.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	vasnprintf, c-vasnprintf: Silence gcc warning.
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 010190d275..d73ee2c894 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -34,13 +34,6 @@
 #include "hash-triple.h"
 #include "xalloc.h"
 
-/* Suppress bogus GCC -Wmaybe-uninitialized warnings.  */
-#if defined GCC_LINT || defined lint
-# define IF_LINT(Code) Code
-#else
-# define IF_LINT(Code) /* empty */
-#endif
-
 #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
 # define DOUBLE_SLASH_IS_DISTINCT_ROOT false
 #endif
@@ -51,6 +44,11 @@
 # define SLASHES "/"
 #endif
 
+/* Avoid false GCC warning "'end_idx' may be used uninitialized".  */
+#if __GNUC__ + (__GNUC_MINOR__ >= 7) > 4
+# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+
 /* Return true if FILE's existence can be shown, false (setting errno)
    otherwise.  Follow symbolic links.  */
 static bool
@@ -369,7 +367,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
               buf[n] = '\0';
 
               char *extra_buf = bufs->extra.data;
-              idx_t end_idx IF_LINT (= 0);
+              idx_t end_idx;
               if (end_in_extra_buffer)
                 end_idx = end - extra_buf;
               size_t len = strlen (end);
-- 
2.34.1

>From 56ddb7d9a223691b914328330dad945c4511b6cb Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 18 May 2023 22:44:40 +0200
Subject: [PATCH 2/2] getndelim2: Silence gcc warning.

* lib/getndelim2.c: Add #pragma GCC diagnostic.
(IF_LINT): Remove macro.
(getndelim2): Remove use of IF_LINT.
---
 ChangeLog        |  7 +++++++
 lib/getndelim2.c | 10 ++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 717789d423..8e980741c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-05-18  Bruno Haible  <br...@clisp.org>
+
+	getndelim2: Silence gcc warning.
+	* lib/getndelim2.c: Add #pragma GCC diagnostic.
+	(IF_LINT): Remove macro.
+	(getndelim2): Remove use of IF_LINT.
+
 2023-05-18  Bruno Haible  <br...@clisp.org>
 
 	canonicalize: Silence gcc warning.
diff --git a/lib/getndelim2.c b/lib/getndelim2.c
index d61ce3a494..b2a40ac5ce 100644
--- a/lib/getndelim2.c
+++ b/lib/getndelim2.c
@@ -50,11 +50,9 @@
 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 #endif
 
-/* Use this to suppress gcc's "...may be used before initialized" warnings. */
-#if defined GCC_LINT || defined lint
-# define IF_LINT(Code) Code
-#else
-# define IF_LINT(Code) /* empty */
+/* Avoid false GCC warning "'c' may be used uninitialized".  */
+#if __GNUC__ + (__GNUC_MINOR__ >= 7) > 4
+# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #endif
 
 /* The maximum value that getndelim2 can return without suffering from
@@ -108,7 +106,7 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
       /* Here always ptr + size == read_pos + nbytes_avail.
          Also nbytes_avail > 0 || size < nmax.  */
 
-      int c IF_LINT (= 0);
+      int c;
       const char *buffer;
       size_t buffer_len;
 
-- 
2.34.1

Reply via email to