From 3d7229c2507be1daf0c3e15e1f134076fa8b9025 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 4 Jan 2017 23:32:14 +0000 Subject: Fix malloc/ tests for GCC 7 -Walloc-size-larger-than=. GCC 7 has a -Walloc-size-larger-than= warning for allocations of half the address space or more. This causes errors building glibc tests that deliberately test failure of very large allocations. This patch arranges for this warning to be ignored around the problematic function calls. Tested compilation for aarch64 (GCC mainline) with build-many-glibcs.py; did execution testing for x86_64 (GCC 5). * malloc/tst-malloc.c: Include . (do_test): Disable -Walloc-size-larger-than= around tests of malloc with negative sizes. * malloc/tst-mcheck.c: Include . (do_test): Disable -Walloc-size-larger-than= around tests of malloc and realloc with negative sizes. * malloc/tst-realloc.c: Include . (do_test): Disable -Walloc-size-larger-than= around tests of realloc with negative sizes. --- malloc/tst-mcheck.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'malloc/tst-mcheck.c') diff --git a/malloc/tst-mcheck.c b/malloc/tst-mcheck.c index 73a497f988..2e3cba96b8 100644 --- a/malloc/tst-mcheck.c +++ b/malloc/tst-mcheck.c @@ -19,6 +19,7 @@ #include #include #include +#include static int errors = 0; @@ -36,7 +37,14 @@ do_test (void) errno = 0; + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* GCC 7 warns about too-large allocations; here we want to test + that they fail. */ + DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than="); +#endif p = malloc (-1); + DIAG_POP_NEEDS_COMMENT; if (p != NULL) merror ("malloc (-1) succeeded."); @@ -67,10 +75,17 @@ do_test (void) if (p == NULL) merror ("malloc (512) failed."); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* GCC 7 warns about too-large allocations; here we want to test + that they fail. */ + DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than="); +#endif if (realloc (p, -256) != NULL) merror ("realloc (p, -256) succeeded."); else if (errno != ENOMEM) merror ("errno is not set correctly."); + DIAG_POP_NEEDS_COMMENT; free (p); @@ -78,10 +93,17 @@ do_test (void) if (p == NULL) merror ("malloc (512) failed."); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* GCC 7 warns about too-large allocations; here we want to test + that they fail. */ + DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than="); +#endif if (realloc (p, -1) != NULL) merror ("realloc (p, -1) succeeded."); else if (errno != ENOMEM) merror ("errno is not set correctly."); + DIAG_POP_NEEDS_COMMENT; free (p); free (q); -- cgit 1.4.1