1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2026-10-24 00:48:56 +03:00

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.
This commit is contained in:
Paul Eggert
2026-09-23 17:44:26 -07:00
parent 75659d5c2c
commit 689a146283
12 changed files with 22 additions and 58 deletions

View File

@@ -1,5 +1,14 @@
2026-09-23 Paul Eggert <eggert@cs.ucla.edu>
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.

View File

@@ -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)

View File

@@ -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);

View File

@@ -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 ()

View File

@@ -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)

View File

@@ -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 ()

View File

@@ -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

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);

View File

@@ -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

View File

@@ -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