diff --git a/ChangeLog b/ChangeLog index 16a3c3020e..a440b6d3f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2026-09-23 Paul Eggert + tests: prefer GCC sanitization macros + * tests/test-c-stack.c, tests/test-calloc-posix.c: + * tests/test-dprintf-posix2.c, tests/test-explicit_bzero.c: + * tests/test-fprintf-posix3.c, tests/test-free.c: + * tests/test-malloc-posix.c, tests/test-memset_explicit.c: + * tests/test-reallocarray.c, tests/test-sigsegv-catch-stackoverflow1.c: + * tests/test-sigsegv-catch-stackoverflow2.c: + Simplify now that gnulib-common.m4 supports GCC-like macros. + getdelim: check for other sanitizers * lib/stdio.in.h (__has_feature): Remove. (getdelim): Also check for other relevant sanitizers. diff --git a/tests/test-c-stack.c b/tests/test-c-stack.c index 80b9edd09c..5528d5c746 100644 --- a/tests/test-c-stack.c +++ b/tests/test-c-stack.c @@ -31,10 +31,7 @@ #include "macros.h" /* Skip this test when an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ int main (int argc, char **argv) diff --git a/tests/test-calloc-posix.c b/tests/test-calloc-posix.c index 3cf2a253cd..627a60d2a2 100644 --- a/tests/test-calloc-posix.c +++ b/tests/test-calloc-posix.c @@ -25,11 +25,6 @@ #include "macros.h" -/* For determining whether an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Work around clang bug . */ void *(*volatile my_calloc) (size_t, size_t) = calloc; @@ -39,7 +34,7 @@ void *(*volatile my_calloc) (size_t, size_t) = calloc; int main () { -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if defined __SANITIZE_ADDRESS__ \ || defined __FILC__ /* Avoid a "filc safety error: attempt to allocate object that is too big" */ fputs ("Skipping test: large allocations are unsupported\n", stderr); diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index a473492e31..a0f18d9223 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -35,10 +35,7 @@ main () #else /* Skip this test when an address sanitizer is in use, since it would fail. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ int main () diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c index f34670cb9e..b0851227f9 100644 --- a/tests/test-explicit_bzero.c +++ b/tests/test-explicit_bzero.c @@ -64,10 +64,7 @@ test_static (void) a "heap use after free". Skip it also with Fil-C, because that environment does not support the conversion of uintptr_t to a pointer or the re-use of a freed pointer. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if defined __SANITIZE_ADDRESS__ \ || defined __FILC__ static void @@ -150,10 +147,7 @@ test_heap (void) /* Skip this part when an address sanitizer is in use, because it would report a "stack use after return". */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ static void test_stack (void) diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c index e3b4a9f605..2282412064 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -39,10 +39,7 @@ main () #else /* Skip this test when an address sanitizer is in use, since it would fail. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ int main () diff --git a/tests/test-free.c b/tests/test-free.c index 612a7afb7f..b1f4ecf395 100644 --- a/tests/test-free.c +++ b/tests/test-free.c @@ -92,10 +92,7 @@ main () /* Skip this test when an address sanitizer is in use, because it would report a "heap buffer overflow". */ - #ifndef __has_feature - #define __has_feature(a) 0 - #endif - #if !(defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)) + #ifndef __SANITIZE_ADDRESS__ /* Test a less common code path. When malloc() is based on mmap(), free() can sometimes call munmap(). munmap() usually succeeds, but fails in a particular situation: when diff --git a/tests/test-malloc-posix.c b/tests/test-malloc-posix.c index 3cc3e83bc2..d821bff556 100644 --- a/tests/test-malloc-posix.c +++ b/tests/test-malloc-posix.c @@ -25,11 +25,6 @@ #include "macros.h" -/* For determining whether an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Work around clang bug . */ void *(*volatile my_malloc) (size_t) = malloc; @@ -39,7 +34,7 @@ void *(*volatile my_malloc) (size_t) = malloc; int main () { -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if defined __SANITIZE_ADDRESS__ \ || defined __FILC__ /* Avoid a "filc safety error: attempt to allocate object that is too big" */ fputs ("Skipping test: large allocations are unsupported\n", stderr); diff --git a/tests/test-memset_explicit.c b/tests/test-memset_explicit.c index 488f07beea..b30cc02ff6 100644 --- a/tests/test-memset_explicit.c +++ b/tests/test-memset_explicit.c @@ -101,10 +101,7 @@ test_static (void) a "heap use after free". Skip it also with Fil-C, because that environment does not support the conversion of uintptr_t to a pointer or the re-use of a freed pointer. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if defined __SANITIZE_ADDRESS__ \ || defined __FILC__ static void @@ -187,10 +184,7 @@ test_heap (void) /* Skip this part when an address sanitizer is in use, because it would report a "stack use after return". */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ static void test_stack (void) diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c index 9b71c520aa..0a692dc558 100644 --- a/tests/test-reallocarray.c +++ b/tests/test-reallocarray.c @@ -28,11 +28,6 @@ SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t)); #include "macros.h" -/* For determining whether an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Work around clang bug . */ void *(*volatile my_reallocarray) (void *, size_t, size_t) = reallocarray; @@ -42,7 +37,7 @@ void *(*volatile my_reallocarray) (void *, size_t, size_t) = reallocarray; int main () { -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if defined __SANITIZE_ADDRESS__ \ || defined __FILC__ /* Avoid a "filc safety error: attempt to allocate object that is too big" */ fputs ("Skipping test: large allocations are unsupported\n", stderr); diff --git a/tests/test-sigsegv-catch-stackoverflow1.c b/tests/test-sigsegv-catch-stackoverflow1.c index 9a9d238fa4..82ade07b13 100644 --- a/tests/test-sigsegv-catch-stackoverflow1.c +++ b/tests/test-sigsegv-catch-stackoverflow1.c @@ -33,10 +33,7 @@ #include /* Skip this test when an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ # undef HAVE_STACK_OVERFLOW_RECOVERY #endif diff --git a/tests/test-sigsegv-catch-stackoverflow2.c b/tests/test-sigsegv-catch-stackoverflow2.c index fc07a26336..b30f5057f0 100644 --- a/tests/test-sigsegv-catch-stackoverflow2.c +++ b/tests/test-sigsegv-catch-stackoverflow2.c @@ -34,10 +34,7 @@ #include /* Skip this test when an address sanitizer is in use. */ -#ifndef __has_feature -# define __has_feature(a) 0 -#endif -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +#ifdef __SANITIZE_ADDRESS__ # undef HAVE_STACK_OVERFLOW_RECOVERY #endif