diff mbox series

[v3,27/29] malloc: Use volatile as compiler barrier in tst-memalign, tst-valloc

Message ID a53c320699b268fd618aaa96bc416dd51724ca22.1727624528.git.fweimer@redhat.com
State New
Headers show
Series Teach glibc about possible page sizes and handle gaps in ld.so | expand

Commit Message

Florian Weimer Sept. 29, 2024, 4:45 p.m. UTC
This is a simpler way to avoid compiler warnings.  Apply this to
the pagesize variable as well, to enable future optimizations.
---
 malloc/tst-memalign.c | 17 ++++++-----------
 malloc/tst-valloc.c   | 17 ++++++-----------
 2 files changed, 12 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/malloc/tst-memalign.c b/malloc/tst-memalign.c
index 563f6413d2..1cfe9312dd 100644
--- a/malloc/tst-memalign.c
+++ b/malloc/tst-memalign.c
@@ -35,25 +35,20 @@  merror (const char *msg)
 static int
 do_test (void)
 {
+  /* Use volatile for compiler barriers, to avoid
+     Walloc-size-larger-than warnings.  */
+  volatile unsigned long int pagesize = getpagesize ();
+  volatile int minus1 = -1;
   void *p;
-  unsigned long pagesize = getpagesize ();
-  unsigned long ptrval;
+  unsigned long int ptrval;
   int save;
 
   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
   /* An attempt to allocate a huge value should return NULL and set
      errno to ENOMEM.  */
-  p = memalign (sizeof (void *), -1);
-#if __GNUC_PREREQ (7, 0)
-  DIAG_POP_NEEDS_COMMENT;
-#endif
+  p = memalign (sizeof (void *), minus1);
 
   save = errno;
 
diff --git a/malloc/tst-valloc.c b/malloc/tst-valloc.c
index 9bab8c6470..b27a6c0fc0 100644
--- a/malloc/tst-valloc.c
+++ b/malloc/tst-valloc.c
@@ -35,25 +35,20 @@  merror (const char *msg)
 static int
 do_test (void)
 {
+  /* Use volatile for compiler barriers, to avoid
+     Walloc-size-larger-than warnings.  */
+  volatile unsigned long int pagesize = getpagesize ();
+  volatile int minus1 = -1;
   void *p;
-  unsigned long pagesize = getpagesize ();
-  unsigned long ptrval;
+  unsigned long int ptrval;
   int save;
 
   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
   /* An attempt to allocate a huge value should return NULL and set
      errno to ENOMEM.  */
-  p = valloc (-1);
-#if __GNUC_PREREQ (7, 0)
-  DIAG_POP_NEEDS_COMMENT;
-#endif
+  p = valloc (minus1);
 
   save = errno;