Subject: Re: CI failure due to warning in diff.c

From: Paul Eggert <[email-masked]>
Date: Wed, 24 May 2023 10:25:45 -0700

On 2023-05-23 09:46, Bruno Haible wrote:

> The diffutils CI reports a build failure:
> 
> 
>    CC       diff.o
> ../../../sources/diffutils/src/diff.c: In function 'compare_files':
> ../../../sources/diffutils/src/diff.c:1209:8: error: missing initializer for field 'name' of 'struct file_data' [-Werror=missing-field-initializers]

I don't know how to find out the details of the diffutils CI build. 
However, I think the bug is probably that the build was using GCC 11.1 
or 11.2, which is buggy in this area. I installed the attached patches 
to Gnulib to work around that problem.

If you're configuring with --enable-gcc-warnings or equivalent, it's 
better to use current GCC. Older versions of GCC have several problems 
in this area, and although I went to the trouble of working around this 
particular problem I doubt whether it's worth our time to worry about 
all false positives generated by older GCC versions, so  it might be 
better to build with --disable-gcc-warnings on older platforms.

From 46a4745434bb3620f5c67df29969fe8bd311870c Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 24 May 2023 09:20:48 -0700
Subject: [PATCH 1/3] manywarnings: port better to GCC 11.2 and earlier

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-diffutils/2023-05/msg00015.html
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC):
Also test for GCC bug 82283
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82283>.
---
 ChangeLog          | 9 +++++++++
 m4/manywarnings.m4 | 7 +++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 01944021be..81057be3d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-05-24  Paul Eggert  <[email-masked]>
+
+	manywarnings: port better to GCC 11.2 and earlier
+	Problem reported by Bruno Haible in:
+	https://lists.gnu.org/r/bug-diffutils/2023-05/msg00015.html
+	* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC):
+	Also test for GCC bug 82283
+	<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82283>.
+
 2023-05-24  Bruno Haible  <[email-masked]>
 
 	asyncsafe-spin, simple-atomic: Don't use -mcpu-v9 on NetBSD/sparc.
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 13db996516..77b96295df 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -69,11 +69,14 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
          CFLAGS="$CFLAGS -Wextra -Werror"
          AC_COMPILE_IFELSE(
            [AC_LANG_PROGRAM(
-              [[int f (void)
+              [[struct file_data { int desc, name; };
+                struct cmp { struct file_data file[1]; };
+                void f (struct cmp *r)
                 {
                   typedef struct { int a; int b; } s_t;
                   s_t s1 = { 0, };
-                  return s1.b;
+                  struct cmp cmp = { .file[0].desc = r->file[0].desc + s1.a };
+                  *r = cmp;
                 }
               ]],
               [[]])],
-- 
2.39.2

From b00ffa282f3c494012a127919f8625e14d89f80d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 24 May 2023 09:23:01 -0700
Subject: [PATCH 2/3] Simplify -Wno-missing-field-initializers checking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): Don’t worry about
-Wmissing-field-initializers, as this is no longer needed now that
gl_MANYWARN_ALL_GCC is fixed.
---
 ChangeLog           | 5 +++++
 m4/gnulib-common.m4 | 4 ----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 81057be3d6..e09a981eec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2023-05-24  Paul Eggert  <[email-masked]>
 
+	Simplify -Wno-missing-field-initializers checking
+	* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): Don’t worry about
+	-Wmissing-field-initializers, as this is no longer needed now that
+	gl_MANYWARN_ALL_GCC is fixed.
+
 	manywarnings: port better to GCC 11.2 and earlier
 	Problem reported by Bruno Haible in:
 	https://lists.gnu.org/r/bug-diffutils/2023-05/msg00015.html
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index a2b53d33dc..2426eb6398 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1053,7 +1053,6 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
     dnl -Wno-float-conversion                 >= 4.9          >= 3.9
     dnl -Wno-float-equal                      >= 3            >= 3.9
     dnl -Wimplicit-fallthrough                >= 7            >= 3.9
-    dnl -Wno-missing-field-initializers       >= 4.0, < 11
     dnl -Wno-pedantic                         >= 4.8          >= 3.9
     dnl -Wno-sign-compare                     >= 3            >= 3.9
     dnl -Wno-sign-conversion                  >= 4.3          >= 3.9
@@ -1079,9 +1078,6 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
       #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wimplicit-fallthrough
       #endif
-      #if __GNUC__ >= 4 && __GNUC__ < 11 && !defined __clang__
-      -Wno-missing-field-initializers
-      #endif
       #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wno-pedantic
       #endif
-- 
2.39.2

From d7fd9391132a93ae482a003a81bd25afcf1973f8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 24 May 2023 10:10:18 -0700
Subject: [PATCH 3/3] manywarnings: speed up nomfi test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Simplify and speed up
on current platforms, by seeing first whether
-Wno-missing-field-initializers is needed (it isn’t), so that
later we don’t need to determine whether it’s supported.
---
 ChangeLog          |  6 +++++
 m4/manywarnings.m4 | 56 +++++++++++++++++-----------------------------
 2 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e09a981eec..95302733ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-05-24  Paul Eggert  <[email-masked]>
 
+	manywarnings: speed up nomfi test
+	* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Simplify and speed up
+	on current platforms, by seeing first whether
+	-Wno-missing-field-initializers is needed (it isn’t), so that
+	later we don’t need to determine whether it’s supported.
+
 	Simplify -Wno-missing-field-initializers checking
 	* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): Don’t worry about
 	-Wmissing-field-initializers, as this is no longer needed now that
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 77b96295df..7792b4f3b4 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -47,43 +47,29 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
   dnl gcc warning categories.
   AC_REQUIRE([AC_PROG_CC])
   AS_IF([test -n "$GCC"], [
-    dnl Check if -Wextra -Werror -Wno-missing-field-initializers is supported
-    dnl with the current $CC $CFLAGS $CPPFLAGS.
-    AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
-      [gl_cv_cc_nomfi_supported],
-      [gl_save_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS -Wextra -Werror -Wno-missing-field-initializers"
+    AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
+      [gl_cv_cc_nomfi_needed],
+      [gl_cv_cc_nomfi_needed=no
+       gl_save_CFLAGS="$CFLAGS"
+       CFLAGS="$CFLAGS -Wextra -Werror"
        AC_COMPILE_IFELSE(
-         [AC_LANG_PROGRAM([[]], [[]])],
-         [gl_cv_cc_nomfi_supported=yes],
-         [gl_cv_cc_nomfi_supported=no])
+         [AC_LANG_PROGRAM(
+            [[struct file_data { int desc, name; };
+              struct cmp { struct file_data file[1]; };
+              void f (struct cmp *r)
+              {
+                typedef struct { int a; int b; } s_t;
+                s_t s1 = { 0, };
+                struct cmp cmp = { .file[0].desc = r->file[0].desc + s1.a };
+                *r = cmp;
+              }
+            ]],
+            [[]])],
+         [],
+         [CFLAGS="$CFLAGS -Wno-missing-field-initializers"
+          AC_COMPILE_IFELSE([],
+            [gl_cv_cc_nomfi_needed=yes])])
        CFLAGS="$gl_save_CFLAGS"
-      ])
-
-    AS_IF([test "$gl_cv_cc_nomfi_supported" = yes], [
-      dnl Now check whether -Wno-missing-field-initializers is needed
-      dnl for the { 0, } construct.
-      AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
-        [gl_cv_cc_nomfi_needed],
-        [gl_save_CFLAGS="$CFLAGS"
-         CFLAGS="$CFLAGS -Wextra -Werror"
-         AC_COMPILE_IFELSE(
-           [AC_LANG_PROGRAM(
-              [[struct file_data { int desc, name; };
-                struct cmp { struct file_data file[1]; };
-                void f (struct cmp *r)
-                {
-                  typedef struct { int a; int b; } s_t;
-                  s_t s1 = { 0, };
-                  struct cmp cmp = { .file[0].desc = r->file[0].desc + s1.a };
-                  *r = cmp;
-                }
-              ]],
-              [[]])],
-           [gl_cv_cc_nomfi_needed=no],
-           [gl_cv_cc_nomfi_needed=yes])
-         CFLAGS="$gl_save_CFLAGS"
-        ])
     ])
 
     dnl Next, check if -Werror -Wuninitialized is useful with the
-- 
2.39.2