diff mbox

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

Message ID alpine.DEB.2.10.1411261731080.854@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers Nov. 26, 2014, 5:31 p.m. UTC
This patch, relative to a tree with
<https://sourceware.org/ml/libc-alpha/2014-11/msg00736.html> (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  <joseph@codesourcery.com>

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

Comments

Roland McGrath Dec. 2, 2014, 7:26 p.m. UTC | #1
The ATTR_NULL approach seems far cleaner to me.  Why disable warnings when
a code cleanup suffices?
diff mbox

Patch

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_PUSH_NEEDS_COMMENT;
+  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;
     }
+  DIAG_POP_NEEDS_COMMENT;
 
   if (pthread_mutex_lock (&m) != 0)
     {