This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Add macros for diagnostic control, use them in locale/weightwc.h
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, libc-alpha at sourceware dot org
- Date: Tue, 25 Nov 2014 14:23:40 -0800
- Subject: Re: Add macros for diagnostic control, use them in locale/weightwc.h
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 10 dot 1411181803130 dot 11642 at digraph dot polyomino dot org dot uk> <alpine dot DEB dot 2 dot 10 dot 1411211705270 dot 2475 at digraph dot polyomino dot org dot uk> <546F79BB dot 80604 at cs dot ucla dot edu> <alpine dot DEB dot 2 dot 10 dot 1411211807540 dot 2475 at digraph dot polyomino dot org dot uk> <546F8FA5 dot 2050702 at cs dot ucla dot edu> <alpine dot DEB dot 2 dot 10 dot 1411212240570 dot 32250 at digraph dot polyomino dot org dot uk> <54701BAA dot 1030805 at cs dot ucla dot edu> <20141125000003 dot 4A4E32C3AD5 at topped-with-meat dot com>
On 11/24/2014 04:00 PM, Roland McGrath wrote:
The only thing I'd like you to do differently is to put more explanation in
the code itself
Thanks, I installed the patch with that change.
>From 27f9b288f9af8ad7862c9852c4e002dbdf8207cc Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 25 Nov 2014 14:12:48 -0800
Subject: [PATCH] fnmatch: work around GCC compiler warning bug with uninit var
* posix/fnmatch_loop.c (FCT): Use a scalar not a one-item array.
This works around a bug with x86-64 GCC 4.9.2 and earlier
where 'gcc -O2 -Wmaybe-uninitialized' incorrectly complains
"../locale/weightwc.h:93:7: warning: '*((void *)&str+4)' may be
used uninitialized in this function [-Wmaybe-uninitialized]".
---
ChangeLog | 9 +++++++++
posix/fnmatch_loop.c | 13 +++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8ee0650..c020ed4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-11-25 Paul Eggert <eggert@cs.ucla.edu>
+
+ fnmatch: work around GCC compiler warning bug with uninit var
+ * posix/fnmatch_loop.c (FCT): Use a scalar not a one-item array.
+ This works around a bug with x86-64 GCC 4.9.2 and earlier
+ where 'gcc -O2 -Wmaybe-uninitialized' incorrectly complains
+ "../locale/weightwc.h:93:7: warning: '*((void *)&str+4)' may be
+ used uninitialized in this function [-Wmaybe-uninitialized]".
+
2014-11-25 Joseph Myers <joseph@codesourcery.com>
* posix/bug-regex31.c (main): Return RES not 0.
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index db6d9d7..1e27913 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -343,7 +343,12 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
#ifdef _LIBC
else if (c == L('[') && *p == L('='))
{
- UCHAR str[1];
+ /* It's important that STR be a scalar variable rather
+ than a one-element array, because GCC (at least 4.9.2
+ -O2 on x86-64) can be confused by the array and
+ diagnose a "used initialized" in a dead branch in the
+ findidx function. */
+ UCHAR str;
uint32_t nrules =
_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
const CHAR *startp = p;
@@ -355,7 +360,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
c = L('[');
goto normal_bracket;
}
- str[0] = c;
+ str = c;
c = *++p;
if (c != L('=') || p[1] != L(']'))
@@ -368,7 +373,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
if (nrules == 0)
{
- if ((UCHAR) *n == str[0])
+ if ((UCHAR) *n == str)
goto matched;
}
else
@@ -383,7 +388,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
# endif
const int32_t *indirect;
int32_t idx;
- const UCHAR *cp = (const UCHAR *) str;
+ const UCHAR *cp = (const UCHAR *) &str;
# if WIDE_CHAR_VERSION
table = (const int32_t *)
--
1.9.3