From: Bruno Haible Date: Wed, 7 May 2025 09:34:47 +0000 (+0200) Subject: Add syntax-check rule against CPU predef misspellings. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a747e0374fcadbc44feaa21e411d757991ec221d;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index a430ffd406..450aa55dba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2025-05-07 Bruno Haible + 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. +# 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. 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 # include 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 @@ int main () 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)); } /* */ -#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) \