Thanks, Bruno, for fixing aligned allocation with scudo.
This reminds me of something I've noticed before: GCC and Clang disagree about how to detect which sanitization forms are in use, which leads to some duplication of code in Gnulib, and also I suspect leads to Gnulib not detect some forms of sanitization that it should because it's kinda inconvenient. I installed the attached patches to work around the problems that I found in this area: they let other parts of Gnulib assume the GCC way of doing things. (Clang has other __has_feature options, but I worried only about the ones related to sanitization.) I updated Savannah's copy of GNU Tar to use the new Gnulib. [email protected], could you please test this? You can use the following shell command to get a copy of bleeding-edge GNU Tar source: git clone --depth 289 --no-single-branch https://git.savannah.gnu.org/git/tar.git
From 10fc3926dde27e2423fb38cf823b2124f069a4e1 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:27:00 -0700 Subject: [PATCH 1/6] Define __SANITIZE_ADDRESS__ etc. a la GCC GCC and Clang disagree on how to say whether sanitization is in use. Specify things the GCC way, so that other parts of Gnulib can assume the GCC way and thus be a bit simpler. * m4/gnulib-common.m4 (gl_COMMON_BODY): Define __SANITIZE_ADDRESS__, __SANITIZE_HWADDRESS__, __SANITIZE_LEAK__, __SANITIZE_THREAD__ consistently with GCC. Also define __SANITIZE_MEMORY__, __SANITIZE_SCUDO__ for consistency: GCC does not support these, but if it ever does these are the likely names. --- ChangeLog | 12 ++++++++++++ m4/gnulib-common.m4 | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b02d5c3b4b..edbbd3b75b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2026-09-23 Paul Eggert <[email protected]> + + Define __SANITIZE_ADDRESS__ etc. a la GCC + GCC and Clang disagree on how to say whether sanitization is in use. + Specify things the GCC way, so that other parts of Gnulib can + assume the GCC way and thus be a bit simpler. + * m4/gnulib-common.m4 (gl_COMMON_BODY): Define __SANITIZE_ADDRESS__, + __SANITIZE_HWADDRESS__, __SANITIZE_LEAK__, __SANITIZE_THREAD__ + consistently with GCC. Also define __SANITIZE_MEMORY__, + __SANITIZE_SCUDO__ for consistency: GCC does not support these, + but if it ever does these are the likely names. + 2026-09-23 Bruno Haible <[email protected]> alignalloc: Don't use aligned_alloc if it is buggy. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 8ddec0e2c9..719c6275e4 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,5 +1,5 @@ # gnulib-common.m4 -# serial 123 +# serial 124 dnl Copyright (C) 2007-2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -934,6 +934,31 @@ AC_DEFUN([gl_COMMON_BODY], [ # define _GL_ATTRIBUTE_RELEASE_CAPABILITY(resource) # endif #endif +]) + AH_VERBATIM([sanitizer_features], +[/* Sanitizer features. */ +#ifdef __has_feature +# if !defined __SANITIZE_ADDRESS__ && __has_feature (address_sanitizer) +# define __SANITIZE_ADDRESS__ 1 +# endif +# if !defined __SANITIZE_HWADDRESS__ && __has_feature (hwaddress_sanitizer) +# define __SANITIZE_HWADDRESS__ 1 +# endif +# if !defined __SANITIZE_LEAK__ && __has_feature (leak_sanitizer) +# define __SANITIZE_LEAK__ 1 +# endif +# if !defined __SANITIZE_THREAD__ && __has_feature (thread_sanitizer) +# define __SANITIZE_THREAD__ 1 +# endif + /* Although the following sanitizers are in Clang not GCC, + define GCC-like macro names for consistency and convenience. */ +# if !defined __SANITIZE_MEMORY__ && __has_feature (memory_sanitizer) +# define __SANITIZE_MEMORY__ 1 +# endif +# if !defined __SANITIZE_SCUDO__ && __has_feature (scudo_sanitizer) +# define __SANITIZE_SCUDO__ 1 +# endif +#endif ]) AH_VERBATIM([c_linkage], [/* In C++, there is the concept of "language linkage", that encompasses -- 2.53.0
From 66613f426cb3fe162c9497abaf599dac1cd79baf Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:33:53 -0700 Subject: [PATCH 2/6] malloc-posix: check for -fsanitize=leak etc * m4/malloc.m4 (gl_CHECK_MALLOC_PTRDIFF): Also be suspicious if HWASan, LSan, MSan, Scudo, TSan, since they can also interpose their own malloc. --- ChangeLog | 5 +++++ m4/malloc.m4 | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index edbbd3b75b..243e6b1a60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2026-09-23 Paul Eggert <[email protected]> + malloc-posix: check for -fsanitize=leak etc + * m4/malloc.m4 (gl_CHECK_MALLOC_PTRDIFF): Also be suspicious + if HWASan, LSan, MSan, Scudo, TSan, since they can also + interpose their own malloc. + Define __SANITIZE_ADDRESS__ etc. a la GCC GCC and Clang disagree on how to say whether sanitization is in use. Specify things the GCC way, so that other parts of Gnulib can diff --git a/m4/malloc.m4 b/m4/malloc.m4 index 567b0e89d6..20505feb81 100644 --- a/m4/malloc.m4 +++ b/m4/malloc.m4 @@ -1,5 +1,5 @@ # malloc.m4 -# serial 47 +# serial 48 dnl Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -119,20 +119,16 @@ AC_DEFUN([gl_CHECK_MALLOC_PTRDIFF], is no problem. */ #define NARROW_SIZE (SIZE_MAX <= PTRDIFF_MAX) - /* Whether address sanitization is in use. - clang 4 through 21 signal this only with __has_feature. */ - #if !defined __SANITIZE_ADDRESS__ && defined __has_feature - # if __has_feature (address_sanitizer) - # define __SANITIZE_ADDRESS__ 1 - # endif - #endif - #if __OpenBSD__ || __NetBSD__ #include <sys/param.h> #endif + #ifndef __has_feature + #define __has_feature(feature) 0 + #endif + /* Many platforms are safe: malloc stays in ptrdiff_t bounds. - However, with address sanitization, gcc (up to at least + However, with some sanitizations, gcc (up to at least gcc 16.1) and clang (up to at least clang 22) interpose a malloc that can go over a 32-bit ptrdiff_t limit. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126436 @@ -142,7 +138,13 @@ AC_DEFUN([gl_CHECK_MALLOC_PTRDIFF], (((2 < __GLIBC__ + (30 <= __GLIBC_MINOR__)) || MUSL_LIBC \ || 11 <= __FreeBSD__ || 800000000 <= __NetBSD_Version__ \ || 201411 <= OpenBSD || defined _WIN32) \ - && !__SANITIZE_ADDRESS__) + && !(__SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ + || __SANITIZE_HWADDRESS__ \ + || __has_feature (hwaddress_sanitizer) \ + || __SANITIZE_LEAK__ || __has_feature (leak_sanitizer) \ + || __has_feature (memory_sanitizer) \ + || __has_feature (scudo_sanitizer) \ + || __SANITIZE_THREAD__ || __has_feature (thread_sanitizer))) #if WIDE_PTRDIFF || NARROW_SIZE || KNOWN_SAFE return 0; -- 2.53.0
From eb7913f5aa7a26257e88ab8b89cc43cce447e26e Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:35:35 -0700 Subject: [PATCH 3/6] closeout: check for -fsanitize=leak etc Do not close stderr if other sanitizers are in use that output to stderr after main exits. * lib/closeout.c (CLOSE_STDERR_TOO): Rename from SANITIZE_ADDRESS and invert sense. Change the use. --- ChangeLog | 6 ++++++ lib/closeout.c | 14 ++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 243e6b1a60..79e5b2cda3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2026-09-23 Paul Eggert <[email protected]> + closeout: check for -fsanitize=leak etc + Do not close stderr if other sanitizers are in use that + output to stderr after main exits. + * lib/closeout.c (CLOSE_STDERR_TOO): Rename from SANITIZE_ADDRESS + and invert sense. Change the use. + malloc-posix: check for -fsanitize=leak etc * m4/malloc.m4 (gl_CHECK_MALLOC_PTRDIFF): Also be suspicious if HWASan, LSan, MSan, Scudo, TSan, since they can also diff --git a/lib/closeout.c b/lib/closeout.c index a41758e4b9..80a8a9b4f1 100644 --- a/lib/closeout.c +++ b/lib/closeout.c @@ -32,14 +32,12 @@ #include "exitfail.h" #include "quotearg.h" -#ifndef __has_feature -# define __has_feature(a) false -#endif - -#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) -enum { SANITIZE_ADDRESS = true }; +#if (defined __SANITIZE_ADDRESS__ || defined __SANITIZE_HWADDRESS__ \ + || defined __SANITIZE_LEAK__ || defined __SANITIZE_MEMORY__ \ + || defined __SANITIZE_SCUDO__ || defined __SANITIZE_THREAD__) +enum { CLOSE_STDERR_TOO = false }; #else -enum { SANITIZE_ADDRESS = false }; +enum { CLOSE_STDERR_TOO = true }; #endif static const char *file_name; @@ -130,6 +128,6 @@ close_stdout (void) /* Close stderr only if not sanitizing, as sanitizers may report to stderr after this function returns. */ - if (!SANITIZE_ADDRESS && close_stream (stderr) != 0) + if (CLOSE_STDERR_TOO && close_stream (stderr) != 0) _exit (exit_failure); } -- 2.53.0
From 261efbba928fbad24334f218b5c3190653bcec18 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:38:48 -0700 Subject: [PATCH 4/6] memchr: check for other sanitizers * lib/memchr.c, lib/memchr2.c, lib/rawmemchr.c, lib/strchrnul.c: (__has_feature): Remove. * lib/memchr.c (__memchr), lib/memchr2.c (memchr2): * lib/rawmemchr.c (rawmemchr), lib/strchrnul.c (strchrnul): Also check for other relevant sanitizers. --- ChangeLog | 7 +++++++ lib/memchr.c | 7 ++----- lib/memchr2.c | 7 ++----- lib/rawmemchr.c | 7 ++----- lib/strchrnul.c | 7 ++----- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79e5b2cda3..c2ad588e56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2026-09-23 Paul Eggert <[email protected]> + memchr: check for other sanitizers + * lib/memchr.c, lib/memchr2.c, lib/rawmemchr.c, lib/strchrnul.c: + (__has_feature): Remove. + * lib/memchr.c (__memchr), lib/memchr2.c (memchr2): + * lib/rawmemchr.c (rawmemchr), lib/strchrnul.c (strchrnul): + Also check for other relevant sanitizers. + closeout: check for -fsanitize=leak etc Do not close stderr if other sanitizers are in use that output to stderr after main exits. diff --git a/lib/memchr.c b/lib/memchr.c index fb1a81ab8e..65948239d6 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -54,10 +54,6 @@ # define __memchr memchr #endif -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Search no more than N bytes of S for C. */ void * __memchr (void const *s, int c_in, size_t n) @@ -70,7 +66,8 @@ __memchr (void const *s, int c_in, size_t n) so suppress this optimization on platforms where it is known to be dangerous, namely, those using address sanitization. */ -#if ! (defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if ! (defined __SANITIZE_ADDRESS__ || defined __SANITIZE_HWADDRESS__ \ + || defined __SANITIZE_MEMORY__ \ || defined __CHERI_PURE_CAPABILITY__) /* On 32-bit hardware, choosing longword to be a 32-bit unsigned diff --git a/lib/memchr2.c b/lib/memchr2.c index 5f9ffd9640..09a8857ade 100644 --- a/lib/memchr2.c +++ b/lib/memchr2.c @@ -29,10 +29,6 @@ #include <stdint.h> #include <string.h> -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Return the first address of either C1 or C2 (treated as unsigned char) that occurs within N bytes of the memory region S. If neither byte appears, return NULL. */ @@ -48,7 +44,8 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n) so suppress this optimization on platforms where it is known to be dangerous, namely, those using address sanitization. */ -#if ! (defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if ! (defined __SANITIZE_ADDRESS__ || defined __SANITIZE_HWADDRESS__ \ + || defined __SANITIZE_MEMORY__ \ || defined __CHERI_PURE_CAPABILITY__) /* On 32-bit hardware, choosing longword to be a 32-bit unsigned diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c index 764d63339e..3376c37f79 100644 --- a/lib/rawmemchr.c +++ b/lib/rawmemchr.c @@ -25,10 +25,6 @@ # include <limits.h> # include <stdint.h> -# ifndef __has_feature -# define __has_feature(a) 0 -# endif - /* Find the first occurrence of C in S. */ void * @@ -53,7 +49,8 @@ rawmemchr (const void *s, int c_in) so suppress this optimization on platforms where it is known to be dangerous, namely, those using address sanitization. */ -# if ! (defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)) +# if ! (defined __SANITIZE_ADDRESS__ || defined __SANITIZE_HWADDRESS__ \ + || defined __SANITIZE_MEMORY__) /* You can change this typedef to experiment with performance. */ typedef uintptr_t longword _GL_ATTRIBUTE_MAY_ALIAS; diff --git a/lib/strchrnul.c b/lib/strchrnul.c index b17afc1833..ef9d2a9c4a 100644 --- a/lib/strchrnul.c +++ b/lib/strchrnul.c @@ -19,10 +19,6 @@ /* Specification. */ #include <string.h> -#ifndef __has_feature -# define __has_feature(a) 0 -#endif - /* Find the first occurrence of C in S or the final NUL byte. */ char * strchrnul (const char *s, int c_in) @@ -37,7 +33,8 @@ strchrnul (const char *s, int c_in) so suppress this optimization on platforms where it is known to be dangerous, namely, those using address sanitization. */ -#if ! (defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) \ +#if ! (defined __SANITIZE_ADDRESS__ || defined __SANITIZE_HWADDRESS__ \ + || defined __SANITIZE_MEMORY__ \ || defined __CHERI_PURE_CAPABILITY__) /* On 32-bit hardware, choosing longword to be a 32-bit unsigned -- 2.53.0
From 75659d5c2c2341fd3f33f0378384642aafb917a1 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:39:43 -0700 Subject: [PATCH 5/6] getdelim: check for other sanitizers * lib/stdio.in.h (__has_feature): Remove. (getdelim): Also check for other relevant sanitizers. --- ChangeLog | 4 ++++ lib/stdio.in.h | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2ad588e56..16a3c3020e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2026-09-23 Paul Eggert <[email protected]> + getdelim: check for other sanitizers + * lib/stdio.in.h (__has_feature): Remove. + (getdelim): Also check for other relevant sanitizers. + memchr: check for other sanitizers * lib/memchr.c, lib/memchr2.c, lib/rawmemchr.c, lib/strchrnul.c: (__has_feature): Remove. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 107ebd6df1..4fb29a7fa6 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -1091,11 +1091,9 @@ _GL_CXXALIASWARN (getchar); # undef getdelim # define getdelim rpl_getdelim # endif -# ifndef __has_feature -# define __has_feature(a) 0 -# endif # if __GLIBC__ >= 2 && !(defined __SANITIZE_ADDRESS__ \ - || __has_feature (address_sanitizer)) + || defined __SANITIZE_LEAK__ \ + || defined __SANITIZE_MEMORY__) /* Arrange for the inline definition of getline() in <bits/stdio.h> to call our getdelim() override. Do not use the __getdelim symbol if address sanitizer is in use, otherwise it may be overridden by -- 2.53.0
From 689a146283ee36356ce5bd8bd2a000e257ed7cbf Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Wed, 23 Sep 2026 17:44:26 -0700 Subject: [PATCH 6/6] 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. --- ChangeLog | 9 +++++++++ tests/test-c-stack.c | 5 +---- tests/test-calloc-posix.c | 7 +------ tests/test-dprintf-posix2.c | 5 +---- tests/test-explicit_bzero.c | 10 ++-------- tests/test-fprintf-posix3.c | 5 +---- tests/test-free.c | 5 +---- tests/test-malloc-posix.c | 7 +------ tests/test-memset_explicit.c | 10 ++-------- tests/test-reallocarray.c | 7 +------ tests/test-sigsegv-catch-stackoverflow1.c | 5 +---- tests/test-sigsegv-catch-stackoverflow2.c | 5 +---- 12 files changed, 22 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16a3c3020e..a440b6d3f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2026-09-23 Paul Eggert <[email protected]> + 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 <https://github.com/llvm/llvm-project/issues/114772>. */ 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 <https://github.com/llvm/llvm-project/issues/114772>. */ 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 <https://github.com/llvm/llvm-project/issues/114772>. */ 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 <limits.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__ # 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 <limits.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__ # undef HAVE_STACK_OVERFLOW_RECOVERY #endif -- 2.53.0
