This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Disable -Waddress for part of nptl/tst-mutex1.c

This patch, relative to a tree with
<> (pending
review) applied, uses diagnostic control pragmas to disable -Waddress
around comparisons in nptl/tst-mutex1.c where comparing the address of
an object with NULL is deliberate (the macro ATTR is NULL when
tst-mutex1.c is used directly, the address of an object when included
from tst-mutexpi1.c, and this is how the test distinguishes).  While
it would of course be possible e.g. to define another macro ATTR_NULL
in a way that avoids the comparison giving rise to the warning, that
seems excessive, and disabling the warning natural, when it's a simple
case of natural code deliberately doing something that gives rise to a
warning because in other circumstances it might not be deliberate.

Tested for x86_64.

2014-11-26  Joseph Myers  <>

	* nptl/tst-mutex1.c: Include <libc-internal.h>.
	(do_test): Disable -Waddress around comparisons ATTR != NULL.

diff --git a/nptl/tst-mutex1.c b/nptl/tst-mutex1.c
index 2a181e5..ef559c6 100644
--- a/nptl/tst-mutex1.c
+++ b/nptl/tst-mutex1.c
@@ -19,6 +19,7 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <errno.h>
+#include <libc-internal.h>
 #ifndef ATTR
@@ -32,6 +33,11 @@ do_test (void)
   pthread_mutex_t m;
   int e = pthread_mutex_init (&m, ATTR);
+  /* When included from tst-mutexpi1.c, there is a warning "the
+     comparison will always evaluate as 'true' for the address of 'a'
+     will never be NULL".  */
+  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Waddress");
   if (ATTR != NULL && e == ENOTSUP)
       puts ("cannot support selected type of mutexes");
@@ -48,6 +54,7 @@ do_test (void)
       puts ("mutexattr_destroy failed");
       return 1;
   if (pthread_mutex_lock (&m) != 0)

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]