This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Add macros for diagnostic control, use them in locale/weightwc.h
- From: Joseph Myers <joseph at codesourcery dot com>
- To: <libc-alpha at sourceware dot org>
- Date: Tue, 18 Nov 2014 18:04:04 +0000
- Subject: Add macros for diagnostic control, use them in locale/weightwc.h
- Authentication-results: sourceware.org; auth=none
In <https://sourceware.org/ml/libc-alpha/2014-11/msg00326.html>,
Roland requested internal macros for use of "#pragma GCC diagnostic".
This patch adds such macros and uses them to disable
-Wmaybe-uninitialized warnings for some code in locale/weightwc.h. I
put a GCC version in the arguments to DIAG_IGNORE, as that seems
something useful to grep for when obsoleting support for an old GCC
version and needing to decide if warning-disabling code is still
relevant.
The use in weightwc.h has a __GNUC_PREREQ (4, 7) conditional because
4.6 doesn't have -Wmaybe-uninitialized (split out of -Wuninitialized
for 4.7). I didn't include a #else case to disable -Wuninitialized
for 4.6 because I don't know if 4.6 produces these warnings (but if
someone does see them with 4.6, such a #else case should be added -
with 4.6 the version number in the DIAG_IGNORE call).
These macros should be usable for replacing existing -Wno-* use in
makefiles (as also suggested by Roland), though I have no plans to
work on that (only on use of the macros in cases where warnings are
currently present that need disabling to use -Werror).
Tested for x86_64 that installed stripped shared libraries are
unchanged by this patch.
2014-11-18 Joseph Myers <joseph@codesourcery.com>
* include/libc-internal.h (DIAG_PUSH): New macro.
(DIAG_POP): Likewise.
(_DIAG_STR1): Likewise.
(_DIAG_STR): Likewise.
(DIAG_IGNORE): Likewise.
* locale/weightwc.h: Include <libc-internal.h>.
(findidx): Disable -Wmaybe-uninitialized around some dereferences
of CP.
diff --git a/include/libc-internal.h b/include/libc-internal.h
index 78f82da..0be89e6 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -70,4 +70,26 @@ extern void __init_misc (int, char **, char **);
#define PTR_ALIGN_UP(base, size) \
((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
+/* Push diagnostic state. */
+#define DIAG_PUSH _Pragma ("GCC diagnostic push")
+
+/* Pop diagnostic state. */
+#define DIAG_POP _Pragma ("GCC diagnostic pop")
+
+#define _DIAG_STR1(s) #s
+#define _DIAG_STR(s) _DIAG_STR1(s)
+
+/* Ignore the diagnostic OPTION. VERSION is the most recent GCC
+ version for which the diagnostic has been confirmed to appear in
+ the absence of the pragma (in the form MAJOR.MINOR for GCC 4.x,
+ just MAJOR for GCC 5 and later). Uses of this pragma should be
+ reviewed when the GCC version given is no longer supported for
+ building glibc. Uses should come with a comment giving more
+ details of the diagnostic, and an architecture on which it is seen
+ if possibly optimization-related and not in architecture-specific
+ code. This macro should only be used if the diagnostic seems hard
+ to fix (for example, optimization-related false positives). */
+#define DIAG_IGNORE(option, version) \
+ _Pragma (_DIAG_STR (GCC diagnostic ignored _DIAG_STR (option)))
+
#endif /* _LIBC_INTERNAL */
diff --git a/locale/weightwc.h b/locale/weightwc.h
index 0f70b00..d79bd21 100644
--- a/locale/weightwc.h
+++ b/locale/weightwc.h
@@ -19,6 +19,8 @@
#ifndef _WEIGHTWC_H_
#define _WEIGHTWC_H_ 1
+#include <libc-internal.h>
+
/* Find index of weight. */
static inline int32_t __attribute__ ((always_inline))
findidx (const int32_t *table,
@@ -90,6 +92,16 @@ findidx (const int32_t *table,
continue;
}
+ /* Seen on x86_64 (inlined from
+ fnmatch_loop.c:internal_fnwmatch): "'*((void *)&str+4)'
+ may be used uninitialized in this function" (the
+ diagnostic can apply to multiple dereferences of CP, not
+ just one, so all affected dereferences need to be between
+ DIAG_PUSH and DIAG_POP). */
+ 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;
*cpp += nhere;
return indirect[-i + offset];
--
Joseph S. Myers
joseph@codesourcery.com