This is the mail archive of the libc-alpha@sourceware.org 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]

Re: Add macros for diagnostic control, use them in locale/weightwc.h


On 11/18/2014 10:04 AM, Joseph Myers wrote:
+	  DIAG_PUSH;
+#if __GNUC_PREREQ (4, 7)
+	  DIAG_IGNORE (-Wmaybe-uninitialized, 4.9);
+#endif
  	  if (cp[nhere - 1] > usrc[nhere -1])
  	    {
  	      cp += 2 * nhere;
@@ -105,6 +117,7 @@ findidx (const int32_t *table,
  	  /* This range matches the next characters.  Now find
  	     the offset in the indirect table.  */
  	  offset = usrc[nhere - 1] - cp[nhere - 1];
+	  DIAG_POP;

My kneejerk reaction is that attempting to minimize the scope of disabled warnings will make code harder to read and maintain, and the costs of minimization may outweigh the benefits.

Also, the distinction between GCC version "4, 7" (which is checked) and version "4.9" (which is not) is bothersome. Inevitably the unchecked version numbers will become wrong. If we're going to have a "4.9" at all, we should check it.

How about the attached (untested) patch instead? This is simpler and less intrusive and should scale better. It disables the diagnostic in some places that it doesn't absolutely need to, but it separates concerns better and overall I expect it would have a better cost-to-benefit ratio.
diff --git a/ChangeLog b/ChangeLog
index 37b1459..ab9dc88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* locale/weightwc.h (findidx): Disable -Wmaybe-uninitialized.
+
 2014-11-18  Roland McGrath  <roland@hack.frob.com>
 
 	* nptl/createthread.c: New file.
diff --git a/locale/weightwc.h b/locale/weightwc.h
index 0f70b00..383d34e 100644
--- a/locale/weightwc.h
+++ b/locale/weightwc.h
@@ -19,6 +19,14 @@
 #ifndef _WEIGHTWC_H_
 #define _WEIGHTWC_H_	1
 
+#pragma GCC diagnostic push
+
+/* Seen on x86_64 (inlined from fnmatch_loop.c:internal_fnwmatch):
+   "'*((void *)&str+4)' may be used uninitialized in this function".  */
+#if __GNUC_PREREQ (4, 7) && !__GNUC_PREPREQ (4, 10)
+# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+
 /* Find index of weight.  */
 static inline int32_t __attribute__ ((always_inline))
 findidx (const int32_t *table,
@@ -115,4 +123,6 @@ findidx (const int32_t *table,
   return 0x43219876;
 }
 
+#pragma GCC diagnostic pop
+
 #endif	/* weightwc.h */

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