bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenMandriva


From: Bruno Haible
Subject: Re: OpenMandriva
Date: Tue, 27 Aug 2024 00:26:30 +0200

I did:
>       Fix compilation errors with clang that masquerades as gcc 13.

And here is a patch that fixes the clang warnings that appear to be caused
by this version of __GNUC__.

Previously I did not like the __GNUC_PREREQ (glibc) or _GL_GNUC_PREREQ (gnulib)
macro, because they seemed like unnecessary macrology. But now that
_GL_GNUC_PREREQ filters out the lying clang binaries, this macro helps
keeping the code small.


2024-08-26  Bruno Haible  <bruno@clisp.org>

        Fix some of the warnings from a clang that masquerades as gcc 13.
        * lib/c-stack.c: Use _GL_GNUC_PREREQ to test for the gcc version.
        * lib/canonicalize.c: Likewise.
        * lib/diffseq.h: Likewise.
        * lib/file-has-acl.c: Likewise.
        * lib/freopen-safer.c: Likewise.
        * lib/getndelim2.c: Likewise.
        * lib/mini-gmp-gnulib.c: Likewise.
        * lib/propername.c: Likewise.
        * lib/quotearg.c: Likewise.
        * lib/savedir.c: Likewise.
        * lib/vasnprintf.c: Likewise.
        * tests/test-argmatch.c: Likewise.
        * tests/test-dup2.c: Likewise.
        * tests/test-explicit_bzero.c: Likewise.
        * tests/test-fcntl.c: Likewise.
        * tests/test-fopen.h: Likewise.
        * tests/test-getdtablesize.c: Likewise.
        * tests/test-getgroups.c: Likewise.
        * tests/test-listen.c: Likewise.
        * tests/test-localename.c: Likewise.
        * tests/test-memset_explicit.c: Likewise.
        * tests/test-open.h: Likewise.
        * tests/test-perror2.c: Likewise.
        * tests/test-select.h: Likewise.
        * lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD): Don't use
        gnu_printf with clang.
        * lib/string-buffer.h: Likewise.
        * lib/textstyle.in.h: Likewise.

diff --git a/lib/c-stack.c b/lib/c-stack.c
index b8974d3489..0e14de9423 100644
--- a/lib/c-stack.c
+++ b/lib/c-stack.c
@@ -130,7 +130,7 @@ null_action (_GL_UNUSED int signo)
 }
 
 /* Pacify GCC 9.3.1, which otherwise would complain about segv_handler.  */
-# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# if _GL_GNUC_PREREQ (4, 6)
 #  pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
 # endif
 
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 52e9b3b371..7d2a629024 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -45,7 +45,7 @@
 #endif
 
 /* Avoid false GCC warning "'end_idx' may be used uninitialized".  */
-#if __GNUC__ + (__GNUC_MINOR__ >= 7) > 4
+#if _GL_GNUC_PREREQ (4, 7)
 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #endif
 
diff --git a/lib/diffseq.h b/lib/diffseq.h
index f86ac4f7ee..c9369e4410 100644
--- a/lib/diffseq.h
+++ b/lib/diffseq.h
@@ -95,10 +95,10 @@
 /* Suppress gcc's "...may be used before initialized" warnings,
    generated by GCC versions up to at least GCC 14.2.
    Likewise for gcc -fanalyzer's "use of uninitialized value" warnings.  */
-#if 4 <= __GNUC__ + (7 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 7)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
-# if 13 <= __GNUC__
+# if _GL_GNUC_PREREQ (13, 0)
 #  pragma GCC diagnostic ignored "-Wanalyzer-use-of-uninitialized-value"
 # endif
 #endif
@@ -558,7 +558,7 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET 
ylim,
   #undef XREF_YREF_EQUAL
 }
 
-#if 4 <= __GNUC__ + (7 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 7)
 # pragma GCC diagnostic pop
 #endif
 
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 898fb030d1..06759a4948 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -17,14 +17,14 @@
 
    Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible.  */
 
+#include <config.h>
+
 /* Without this pragma, gcc 4.7.0 20120126 may suggest that the
    file_has_acl function might be candidate for attribute 'const'  */
-#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+#if _GL_GNUC_PREREQ (4, 6)
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
 #endif
 
-#include <config.h>
-
 #include "acl.h"
 
 #include "acl-internal.h"
diff --git a/lib/freopen-safer.c b/lib/freopen-safer.c
index 3a7f568114..14cb5fcbee 100644
--- a/lib/freopen-safer.c
+++ b/lib/freopen-safer.c
@@ -28,7 +28,7 @@
 #include <unistd.h>
 
 /* GCC 13 misunderstands the dup2 trickery in this file.  */
-#if 13 <= __GNUC__
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 #endif
 
diff --git a/lib/getndelim2.c b/lib/getndelim2.c
index dc11f8dd21..89989aefdd 100644
--- a/lib/getndelim2.c
+++ b/lib/getndelim2.c
@@ -47,7 +47,7 @@
 #include "memchr2.h"
 
 /* Avoid false GCC warning "'c' may be used uninitialized".  */
-#if __GNUC__ + (__GNUC_MINOR__ >= 7) > 4
+#if _GL_GNUC_PREREQ (4, 7)
 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #endif
 
diff --git a/lib/mini-gmp-gnulib.c b/lib/mini-gmp-gnulib.c
index 6e02d3cefb..764323f8f7 100644
--- a/lib/mini-gmp-gnulib.c
+++ b/lib/mini-gmp-gnulib.c
@@ -31,11 +31,11 @@
 #include "mini-gmp.h"
 
 /* Pacify GCC -Wsuggest-attribute=const, pure, malloc.  */
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 6)
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
 #endif
-#if 8 <= __GNUC__
+#if _GL_GNUC_PREREQ (8, 0)
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=malloc"
 #endif
 
diff --git a/lib/propername.c b/lib/propername.c
index 7e072d35b6..602ff093bb 100644
--- a/lib/propername.c
+++ b/lib/propername.c
@@ -15,14 +15,14 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
+#include <config.h>
+
 /* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
    the proper_name function might be candidate for attribute 'const'  */
-#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+#if _GL_GNUC_PREREQ (4, 6)
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
 #endif
 
-#include <config.h>
-
 /* Specification.  */
 #include "propername.h"
 
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 5ca511a492..8e359beead 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -17,15 +17,15 @@
 
 /* Written by Paul Eggert <eggert@twinsun.com> */
 
+#include <config.h>
+
 /* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
    the quoting_options_from_style function might be candidate for
    attribute 'pure'  */
-#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+#if _GL_GNUC_PREREQ (4, 6)
 # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
 #endif
 
-#include <config.h>
-
 #include "quotearg.h"
 #include "quote.h"
 
diff --git a/lib/savedir.c b/lib/savedir.c
index 80049ca1de..a902635f2c 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -39,7 +39,7 @@
 #include "xalloc.h"
 
 /* Pacify GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113963>.  */
-#if 13 <= __GNUC__
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
 # pragma GCC diagnostic ignored "-Wanalyzer-null-dereference"
 #endif
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 67277d5ffe..9ace64b5be 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -178,7 +178,7 @@
    standardized by ISO C99 and POSIX.
    _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD  */
 /* __gnu_printf__ is supported in GCC >= 4.4.  */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4) && !defined __clang__
 # define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
 #else
 # define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
diff --git a/lib/string-buffer.h b/lib/string-buffer.h
index 75fd7cbef8..c854aaa809 100644
--- a/lib/string-buffer.h
+++ b/lib/string-buffer.h
@@ -55,7 +55,7 @@ extern int sb_append (struct string_buffer *buffer, const 
char *str);
    Returns 0, or -1 in case of error.  */
 extern int sb_appendvf (struct string_buffer *buffer,
                         const char *formatstring, va_list list)
-  #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+  #if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4) && !defined __clang__
   ATTRIBUTE_FORMAT ((__gnu_printf__, 2, 0))
   #else
   ATTRIBUTE_FORMAT ((__printf__, 2, 0))
@@ -67,7 +67,7 @@ extern int sb_appendvf (struct string_buffer *buffer,
    Returns 0, or -1 in case of error.  */
 extern int sb_appendf (struct string_buffer *buffer,
                         const char *formatstring, ...)
-  #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+  #if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4) && !defined __clang__
   ATTRIBUTE_FORMAT ((__gnu_printf__, 2, 3))
   #else
   ATTRIBUTE_FORMAT ((__printf__, 2, 3))
diff --git a/lib/textstyle.in.h b/lib/textstyle.in.h
index 3cbd5c04c3..39eab0576e 100644
--- a/lib/textstyle.in.h
+++ b/lib/textstyle.in.h
@@ -52,7 +52,7 @@
    _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD  */
 /* __gnu_printf__ is supported in GCC >= 4.4.  */
 #ifndef _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4) && !defined __clang__
 #  define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
 # else
 #  define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 8efb9ebee2..6ae95ca5dd 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -64,7 +64,7 @@
 /* As of GCC 11.2.1, gcc -Wanalyzer-too-complex reports that main's
    use of CHECK macros expands to code that is too complicated for gcc
    -fanalyzer.  Suppress the resulting bogus warnings.  */
-#if 10 <= __GNUC__
+#if _GL_GNUC_PREREQ (10, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
 #endif
 
@@ -968,7 +968,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
 /* Avoid pointless GCC warning "argument 1 value '18446744073709551615' exceeds
    maximum object size 9223372036854775807", triggered by the use of xsum as
    argument of malloc.  */
-# if __GNUC__ >= 7
+# if _GL_GNUC_PREREQ (7, 0)
 #  pragma GCC diagnostic push
 #  pragma GCC diagnostic ignored "-Walloc-size-larger-than="
 # endif
@@ -1029,7 +1029,7 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
   return c_ptr;
 }
 
-# if __GNUC__ >= 7
+# if _GL_GNUC_PREREQ (7, 0)
 #  pragma GCC diagnostic pop
 # endif
 
diff --git a/tests/test-argmatch.c b/tests/test-argmatch.c
index d8f6d09733..6128b7f89e 100644
--- a/tests/test-argmatch.c
+++ b/tests/test-argmatch.c
@@ -22,7 +22,7 @@
 /* As of GCC 11.2.1, gcc -Wanalyzer-too-complex reports that main's
    use of CHECK macros expands to code that is too complicated for gcc
    -fanalyzer.  Suppress the resulting bogus warnings.  */
-#if 10 <= __GNUC__
+#if _GL_GNUC_PREREQ (10, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
 #endif
 
diff --git a/tests/test-dup2.c b/tests/test-dup2.c
index be1e022a0a..464478529f 100644
--- a/tests/test-dup2.c
+++ b/tests/test-dup2.c
@@ -51,7 +51,7 @@ SIGNATURE_CHECK (dup2, int, (int, int));
 #include "macros.h"
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-use-without-check"
 #endif
diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c
index 1c0fd8e6e2..4f576da7c3 100644
--- a/tests/test-explicit_bzero.c
+++ b/tests/test-explicit_bzero.c
@@ -42,7 +42,7 @@ static char zero[SECRET_SIZE] = { 0 };
 #endif
 
 /* Suppress GCC 13.2.1 false alarm, as this test needs a dangling pointer.  */
-#if 12 <= __GNUC__
+#if _GL_GNUC_PREREQ (12, 0)
 # pragma GCC diagnostic ignored "-Wdangling-pointer"
 #endif
 
@@ -168,10 +168,10 @@ test_stack (void)
    does not eliminate a call to explicit_bzero, even if data flow analysis
    reveals that the stack area is dead at the end of the function.  */
 static bool _GL_ATTRIBUTE_NOINLINE
-# if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
+# if _GL_GNUC_PREREQ (4, 5)
 __attribute__ ((__noclone__))
 # endif
-# if __GNUC__ >= 8
+# if _GL_GNUC_PREREQ (8, 0)
 __attribute__ ((__noipa__))
 # endif
 do_secret_stuff (int volatile pass, char *volatile *volatile last_stackbuf)
diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c
index 933df99ab6..66ab9ccb47 100644
--- a/tests/test-fcntl.c
+++ b/tests/test-fcntl.c
@@ -45,7 +45,7 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...));
 #include "macros.h"
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 # pragma GCC diagnostic ignored "-Wanalyzer-va-arg-type-mismatch"
 #endif
diff --git a/tests/test-fopen.h b/tests/test-fopen.h
index 5267362224..5fdb6f94a3 100644
--- a/tests/test-fopen.h
+++ b/tests/test-fopen.h
@@ -24,7 +24,7 @@
 #include "macros.h"
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 10
+#if _GL_GNUC_PREREQ (10, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-file-leak"
 #endif
 
diff --git a/tests/test-getdtablesize.c b/tests/test-getdtablesize.c
index e826c634a9..614be06d98 100644
--- a/tests/test-getdtablesize.c
+++ b/tests/test-getdtablesize.c
@@ -26,7 +26,7 @@ SIGNATURE_CHECK (getdtablesize, int, (void));
 #include "macros.h"
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 #endif
 
diff --git a/tests/test-getgroups.c b/tests/test-getgroups.c
index 7a99c012d8..6cdd8630bd 100644
--- a/tests/test-getgroups.c
+++ b/tests/test-getgroups.c
@@ -35,7 +35,7 @@ SIGNATURE_CHECK (getgroups, int, (int, gid_t[]));
    any -W options, because getgroups() is declared with
      __attribute__ ((__access__ (__write_only__, 2, 1)))
  */
-#if __GNUC__ >= 7
+#if _GL_GNUC_PREREQ (7, 0)
 # pragma GCC diagnostic ignored "-Wstringop-overflow"
 #endif
 
diff --git a/tests/test-listen.c b/tests/test-listen.c
index 6ccffaa1d9..b7ce9b435c 100644
--- a/tests/test-listen.c
+++ b/tests/test-listen.c
@@ -28,7 +28,7 @@ SIGNATURE_CHECK (listen, int, (int, int));
 #include "macros.h"
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-use-without-check"
 #endif
 
diff --git a/tests/test-localename.c b/tests/test-localename.c
index 0e64ce6a94..beb976ac5a 100644
--- a/tests/test-localename.c
+++ b/tests/test-localename.c
@@ -36,7 +36,7 @@
 #endif
 
 /* Suppress GCC false positive.  */
-#if __GNUC__ >= 12
+#if _GL_GNUC_PREREQ (12, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-use-of-uninitialized-value"
 #endif
 
diff --git a/tests/test-memset_explicit.c b/tests/test-memset_explicit.c
index e7ac64147c..477415b45f 100644
--- a/tests/test-memset_explicit.c
+++ b/tests/test-memset_explicit.c
@@ -44,7 +44,7 @@ static char zero[SECRET_SIZE] = { 0 };
 #endif
 
 /* Suppress GCC 13.2.1 false alarm, as this test needs a dangling pointer.  */
-#if 12 <= __GNUC__
+#if _GL_GNUC_PREREQ (12, 0)
 # pragma GCC diagnostic ignored "-Wdangling-pointer"
 #endif
 
@@ -178,10 +178,10 @@ test_stack (void)
    does not eliminate a call to memset_explicit, even if data flow analysis
    reveals that the stack area is dead at the end of the function.  */
 static bool _GL_ATTRIBUTE_NOINLINE
-# if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
+# if _GL_GNUC_PREREQ (4, 5)
 __attribute__ ((__noclone__))
 # endif
-# if __GNUC__ >= 8
+# if _GL_GNUC_PREREQ (8, 0)
 __attribute__ ((__noipa__))
 # endif
 do_secret_stuff (int volatile pass, char *volatile *volatile last_stackbuf)
diff --git a/tests/test-open.h b/tests/test-open.h
index 05764356f8..369c926fcf 100644
--- a/tests/test-open.h
+++ b/tests/test-open.h
@@ -17,7 +17,7 @@
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 #endif
 
diff --git a/tests/test-perror2.c b/tests/test-perror2.c
index 5fe25d69fd..295949157d 100644
--- a/tests/test-perror2.c
+++ b/tests/test-perror2.c
@@ -23,7 +23,7 @@
 #include <unistd.h>
 
 /* Tell GCC not to warn about myerr being leaked.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
 #endif
 
diff --git a/tests/test-select.h b/tests/test-select.h
index 4896b67496..74a91c4b93 100644
--- a/tests/test-select.h
+++ b/tests/test-select.h
@@ -38,7 +38,7 @@
 #endif
 
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if __GNUC__ >= 13
+#if _GL_GNUC_PREREQ (13, 0)
 # pragma GCC diagnostic ignored "-Wanalyzer-fd-use-without-check"
 #endif
 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]