To catch typos in predefined C macros, here are three patches.

2025-05-07  Bruno Haible  <br...@clisp.org>

        Add syntax-check rule against CPU predef misspellings.
        * lib/getloadavg.c: Test __alpha, not __alpha__.
        * tests/test-snan-2.c: Likewise.
        * m4/exponentd.m4: Test __arm__, not __arm.
        * lib/utimensat.c: Test __hppa, not __hppa__.
        * tests/qemu.h: Likewise.
        * lib/fma.c: Test __sparc, not __sparc__.
        * tests/qemu.h: Likewise.
        * tests/test-exp2.h: Likewise.
        * tests/test-nonblocking-pipe.h: Likewise.
        * tests/test-snan-1.c: Likewise.
        * tests/test-snan-2.c: Likewise.

        Add syntax-check rule against OS predef misspellings.
        * Makefile (sc_prohibit_misspelled_os_predefs): New target.
        * lib/stat-size.h: Simplify detection of HP-UX.
        * lib/mountlist.c: Fix typo in comment.

        Add syntax-check rule against compiler predef misspellings.
        * Makefile (sc_prohibit_misspelled_compiler_predefs): New target.

>From 1239883b1aad0ac384875a96d117b6079f52b608 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Wed, 7 May 2025 10:52:49 +0200
Subject: [PATCH 1/3] Add syntax-check rule against compiler predef
 misspellings.

* Makefile (sc_prohibit_misspelled_compiler_predefs): New target.
---
 ChangeLog |  5 +++++
 Makefile  | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 738dce26d2..6d1e5f8e3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-05-07  Bruno Haible  <br...@clisp.org>
+
+	Add syntax-check rule against compiler predef misspellings.
+	* Makefile (sc_prohibit_misspelled_compiler_predefs): New target.
+
 2025-05-07  Bruno Haible  <br...@clisp.org>
 
 	Remove obsolete syntax-check rules.
diff --git a/Makefile b/Makefile
index b2d0cec897..767c6eeb6f 100644
--- a/Makefile
+++ b/Makefile
@@ -53,6 +53,23 @@ sc_prohibit_leading_TABs:
 exclude_file_name_regexp--sc_prohibit_leading_TABs = \
   ^(lib/(cdefs\.h|getopt|ieee754|malloc/|mini-|mktime\.c|qsort\.c|reg|strverscmp\.c)|m4/(largefile|std-gnu)|m4/libgcrypt|tests/from-glibc/|tests/test-update-copyright|Makefile|.*/Makefile)
 
+# Cf. <https://github.com/cpredef/predef/blob/master/Compilers.md>
+sc_prohibit_misspelled_compiler_predefs:
+	if test -d .git; then						\
+	  git ls-files m4 lib tests					\
+	    | xargs grep -Ew '($(misspelled_compiler_predefs_or))'		\
+	    && { printf '*** %s\n' 'misspelled predefs' 1>&2; exit 1; }	\
+	    || :							\
+	else :; fi
+misspelled_compiler_predefs_or = $(shell echo $(misspelled_compiler_predefs) | tr -s ' ' '|')
+misspelled_compiler_predefs =\
+  __clang_major		\
+  __clang_minor		\
+  __GNUC		\
+  __GNUC_MAJOR		\
+  __GNUC_MAJOR__	\
+  __GNUC_MINOR		\
+
 sc_prohibit_augmenting_PATH_via_TESTS_ENVIRONMENT:
 	if test -d .git; then						\
 	  url=https://lists.gnu.org/r/bug-gnulib/2010-09/msg00064.html; \
-- 
2.43.0

>From 7b641c8975caec7b3cc4612e417f11b3848eb374 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Wed, 7 May 2025 10:56:03 +0200
Subject: [PATCH 2/3] Add syntax-check rule against OS predef misspellings.

* Makefile (sc_prohibit_misspelled_os_predefs): New target.
* lib/stat-size.h: Simplify detection of HP-UX.
* lib/mountlist.c: Fix typo in comment.
---
 ChangeLog       |  5 +++++
 Makefile        | 32 ++++++++++++++++++++++++++++++++
 lib/mountlist.c |  2 +-
 lib/stat-size.h |  2 +-
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6d1e5f8e3d..a430ffd406 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-05-07  Bruno Haible  <br...@clisp.org>
 
+	Add syntax-check rule against OS predef misspellings.
+	* Makefile (sc_prohibit_misspelled_os_predefs): New target.
+	* lib/stat-size.h: Simplify detection of HP-UX.
+	* lib/mountlist.c: Fix typo in comment.
+
 	Add syntax-check rule against compiler predef misspellings.
 	* Makefile (sc_prohibit_misspelled_compiler_predefs): New target.
 
diff --git a/Makefile b/Makefile
index 767c6eeb6f..7ed889138a 100644
--- a/Makefile
+++ b/Makefile
@@ -70,6 +70,38 @@ misspelled_compiler_predefs =\
   __GNUC_MAJOR__	\
   __GNUC_MINOR		\
 
+# Cf. <https://github.com/cpredef/predef/blob/master/OperatingSystems.md>
+sc_prohibit_misspelled_os_predefs:
+	if test -d .git; then						\
+	  git ls-files m4 lib tests					\
+	    | xargs grep -Ew '($(misspelled_os_predefs_or))'		\
+	    && { printf '*** %s\n' 'misspelled predefs' 1>&2; exit 1; }	\
+	    || :							\
+	else :; fi
+misspelled_os_predefs_or = $(shell echo $(misspelled_os_predefs) | tr -s ' ' '|')
+misspelled_os_predefs =	\
+  __AIX__		\
+  __FreeBSD		\
+  __NetBSD		\
+  __OpenBSD		\
+  __CYGWIN		\
+  __CYGWIN32__		\
+  __MINGW__		\
+  __WIN32__		\
+  __WIN64__		\
+  __GNU__		\
+  __HAIKU		\
+  __hpux__		\
+  __IRIX__		\
+  __sgi__		\
+  __linux		\
+  __minix__		\
+  __sun__		\
+  __unix		\
+  __unix__		\
+  __ZOS__		\
+  __zOS__		\
+
 sc_prohibit_augmenting_PATH_via_TESTS_ENVIRONMENT:
 	if test -d .git; then						\
 	  url=https://lists.gnu.org/r/bug-gnulib/2010-09/msg00064.html; \
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 72bd3f3bb6..dcff6f8319 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -568,7 +568,7 @@ read_file_system_list (bool need_fs_type)
           goto free_then_fail;
       }
     else /* fallback to /proc/self/mounts (/etc/mtab).  */
-# endif /* __linux __ || __ANDROID__ */
+# endif /* __linux__ || __ANDROID__ */
       {
         struct mntent *mnt;
         char const *table = MOUNTED;
diff --git a/lib/stat-size.h b/lib/stat-size.h
index 96aba4adad..bba083cdf0 100644
--- a/lib/stat-size.h
+++ b/lib/stat-size.h
@@ -68,7 +68,7 @@
 # define STP_BLKSIZE(st) ((0 < (st)->st_blksize \
                            && (st)->st_blksize <= (size_t) -1 / 8 + 1)  \
                           ? (st)->st_blksize : DEV_BSIZE)
-# if defined hpux || defined __hpux__ || defined __hpux
+# if defined __hpux
   /* HP-UX counts st_blocks in 1024-byte units.
      This loses when mixing HP-UX and BSD file systems with NFS.  */
 #  define ST_NBLOCKSIZE 1024
-- 
2.43.0

>From a747e0374fcadbc44feaa21e411d757991ec221d Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Wed, 7 May 2025 11:34:47 +0200
Subject: [PATCH 3/3] Add syntax-check rule against CPU predef misspellings.

* lib/getloadavg.c: Test __alpha, not __alpha__.
* tests/test-snan-2.c: Likewise.
* m4/exponentd.m4: Test __arm__, not __arm.
* lib/utimensat.c: Test __hppa, not __hppa__.
* tests/qemu.h: Likewise.
* lib/fma.c: Test __sparc, not __sparc__.
* tests/qemu.h: Likewise.
* tests/test-exp2.h: Likewise.
* tests/test-nonblocking-pipe.h: Likewise.
* tests/test-snan-1.c: Likewise.
* tests/test-snan-2.c: Likewise.
---
 ChangeLog                     | 13 +++++++++++++
 Makefile                      | 30 ++++++++++++++++++++++++++++++
 lib/fma.c                     |  2 +-
 lib/getloadavg.c              |  2 +-
 lib/utimensat.c               |  2 +-
 m4/exponentd.m4               |  4 ++--
 tests/qemu.h                  |  4 ++--
 tests/test-exp2.h             |  2 +-
 tests/test-nonblocking-pipe.h |  2 +-
 tests/test-snan-1.c           |  2 +-
 tests/test-snan-2.c           |  4 ++--
 11 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a430ffd406..450aa55dba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2025-05-07  Bruno Haible  <br...@clisp.org>
 
+	Add syntax-check rule against CPU predef misspellings.
+	* lib/getloadavg.c: Test __alpha, not __alpha__.
+	* tests/test-snan-2.c: Likewise.
+	* m4/exponentd.m4: Test __arm__, not __arm.
+	* lib/utimensat.c: Test __hppa, not __hppa__.
+	* tests/qemu.h: Likewise.
+	* lib/fma.c: Test __sparc, not __sparc__.
+	* tests/qemu.h: Likewise.
+	* tests/test-exp2.h: Likewise.
+	* tests/test-nonblocking-pipe.h: Likewise.
+	* tests/test-snan-1.c: Likewise.
+	* tests/test-snan-2.c: Likewise.
+
 	Add syntax-check rule against OS predef misspellings.
 	* Makefile (sc_prohibit_misspelled_os_predefs): New target.
 	* lib/stat-size.h: Simplify detection of HP-UX.
diff --git a/Makefile b/Makefile
index 7ed889138a..0ffc677946 100644
--- a/Makefile
+++ b/Makefile
@@ -70,6 +70,36 @@ misspelled_compiler_predefs =\
   __GNUC_MAJOR__	\
   __GNUC_MINOR		\
 
+# Cf. <https://github.com/cpredef/predef/blob/master/Architectures.md>
+# Only the users of module 'host-cpu-c-abi' are allowed to use __${arch}__
+# for all architectures.
+sc_prohibit_misspelled_cpu_predefs:
+	if test -d .git; then						\
+	  git ls-files m4 lib tests					\
+	    | grep -Ev '^(m4/host-cpu-c-abi\.m4|lib/sigsegv\.(in\.h|c)|tests/test-sigsegv.*|tests/jit/test-cache\.c)$$' \
+	    | xargs grep -Ew '($(misspelled_cpu_predefs_or))'		\
+	    && { printf '*** %s\n' 'misspelled predefs' 1>&2; exit 1; }	\
+	    || :							\
+	else :; fi
+misspelled_cpu_predefs_or = $(shell echo $(misspelled_cpu_predefs) | tr -s ' ' '|')
+misspelled_cpu_predefs =\
+  __alpha__		\
+  __amd64		\
+  __x86_64		\
+  __arm			\
+  __arm64		\
+  __arm64__		\
+  __aarch64		\
+  __hppa__		\
+  __loongarch64__	\
+  __m68k		\
+  __riscv__		\
+  __riscv64		\
+  __riscv64__		\
+  __sparc__		\
+  __sparc64		\
+  __sparc64__		\
+
 # Cf. <https://github.com/cpredef/predef/blob/master/OperatingSystems.md>
 sc_prohibit_misspelled_os_predefs:
 	if test -d .git; then						\
diff --git a/lib/fma.c b/lib/fma.c
index c812f3cea0..63108d6fed 100644
--- a/lib/fma.c
+++ b/lib/fma.c
@@ -72,7 +72,7 @@
 #endif
 
 /* Work around GCC 4.2.1 bug on OpenBSD 5.1/SPARC64.  */
-#if defined __GNUC__ && defined __sparc__
+#if defined __GNUC__ && defined __sparc
 # define VOLATILE volatile
 #else
 # define VOLATILE
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index b4fb169182..752ec1f5ae 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -140,7 +140,7 @@
 #  define SUNOS_5
 # endif
 
-# if defined (__osf__) && (defined (__alpha) || defined (__alpha__))
+# if defined (__osf__) && defined (__alpha)
 #  define OSF_ALPHA
 #  include <sys/mbuf.h>
 #  include <sys/socket.h>
diff --git a/lib/utimensat.c b/lib/utimensat.c
index ca1d39e590..fcf2d27eb3 100644
--- a/lib/utimensat.c
+++ b/lib/utimensat.c
@@ -118,7 +118,7 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
             ts[1] = times[1];
           times = ts;
         }
-#   if defined __hppa__ || defined __NetBSD__
+#   if defined __hppa || defined __NetBSD__
       /* Linux kernel 2.6.22.19 on hppa does not reject invalid tv_nsec
          values.
 
diff --git a/m4/exponentd.m4 b/m4/exponentd.m4
index 182a0814a8..08e933970f 100644
--- a/m4/exponentd.m4
+++ b/m4/exponentd.m4
@@ -1,5 +1,5 @@
 # exponentd.m4
-# serial 4
+# serial 5
 dnl Copyright (C) 2007-2008, 2010-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -85,7 +85,7 @@ AC_DEFUN_ONCE([gl_DOUBLE_EXPONENT_LOCATION]
           dnl The newer VFP instructions assume little-endian order
           dnl consistently.
           AC_EGREP_CPP([mixed_endianness], [
-#if defined arm || defined __arm || defined __arm__
+#if defined __arm__
   mixed_endianness
 #endif
             ],
diff --git a/tests/qemu.h b/tests/qemu.h
index f565f00735..88dbfbf38e 100644
--- a/tests/qemu.h
+++ b/tests/qemu.h
@@ -65,7 +65,7 @@ is_running_under_qemu_user (void)
       if (n > 0)
         {
           buf[n] = '\0';
-# if defined __hppa__
+# if defined __hppa
           if (strstr (buf, "QEMU") != NULL)
             return true;
 # endif
@@ -79,7 +79,7 @@ is_running_under_qemu_user (void)
               || strcasestr (buf, "aarch64") != NULL)
             return true;
 # endif
-# if !defined __sparc__
+# if !defined __sparc
           if (strcasestr (buf, "SPARC") != NULL)
             return true;
 # endif
diff --git a/tests/test-exp2.h b/tests/test-exp2.h
index 7a8e238f40..bed46a2dac 100644
--- a/tests/test-exp2.h
+++ b/tests/test-exp2.h
@@ -36,7 +36,7 @@ test_function (void)
     ASSERT (y == L_(1.0));
   }
   /* <https://sourceware.org/bugzilla/show_bug.cgi?id=13824> */
-#if !(__GLIBC__ == 2 && __GLIBC_MINOR__ < 16 && (defined __sparc__ || defined __powerpc__))
+#if !(__GLIBC__ == 2 && __GLIBC_MINOR__ < 16 && (defined __sparc || defined __powerpc__))
   {
     int e;
     DOUBLE x;
diff --git a/tests/test-nonblocking-pipe.h b/tests/test-nonblocking-pipe.h
index 42c24b18dd..db4e59a31f 100644
--- a/tests/test-nonblocking-pipe.h
+++ b/tests/test-nonblocking-pipe.h
@@ -37,7 +37,7 @@
  */
 #if defined __MVS__ || defined __osf__ || (defined __linux__ && (defined __ia64__ || defined __mips__))
 # define PIPE_DATA_BLOCK_SIZE 270000
-#elif defined __linux__ && defined __sparc__
+#elif defined __linux__ && defined __sparc
 # define PIPE_DATA_BLOCK_SIZE 140000
 #elif defined __linux__ && defined __powerpc__
 # define PIPE_DATA_BLOCK_SIZE 1100000
diff --git a/tests/test-snan-1.c b/tests/test-snan-1.c
index 42228c3ee7..a958e9af0b 100644
--- a/tests/test-snan-1.c
+++ b/tests/test-snan-1.c
@@ -90,7 +90,7 @@ main ()
      This test does not work on MSVC/i386, because of the general IA-32
      problem (see above) and 'long double' == 'double'.  */
   #if !((((__GLIBC__ == 2 && __GLIBC_MINOR__ < 19 && defined __mips64) \
-          || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __mips64__ || defined __sparc__))) \
+          || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __mips64__ || defined __sparc))) \
          && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \
         || ((defined __i386 || defined _M_IX86) && HAVE_SAME_LONG_DOUBLE_AS_DOUBLE))
   {
diff --git a/tests/test-snan-2.c b/tests/test-snan-2.c
index 4586c2d9af..b423b12f84 100644
--- a/tests/test-snan-2.c
+++ b/tests/test-snan-2.c
@@ -115,10 +115,10 @@ main (int argc, char *argv[])
            This test does not work on Cygwin 2.9.0/i386. Cause unknown.
            This test does not work on MSVC/i386, because of the general IA-32
            problem (see above) and 'long double' == 'double'.  */
-        #if !((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36 && defined __alpha__) \
+        #if !((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36 && defined __alpha) \
               || (__GLIBC__ >= 2 && defined __loongarch__) \
               || (((__GLIBC__ == 2 && __GLIBC_MINOR__ < 19 && defined __mips64) \
-                   || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __mips64__ || defined __sparc__))) \
+                   || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __mips64__ || defined __sparc))) \
                   && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \
               || (defined __CYGWIN__ && defined __i386) \
               || (((defined __i386 || defined _M_IX86) \
-- 
2.43.0

Reply via email to