From patchwork Sat Nov 22 05:14:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 3849 Received: (qmail 12763 invoked by alias); 22 Nov 2014 05:14:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12749 invoked by uid 89); 22 Nov 2014 05:14:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.cs.ucla.edu Message-ID: <54701BAA.1030805@cs.ucla.edu> Date: Fri, 21 Nov 2014 21:14:18 -0800 From: Paul Eggert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Joseph Myers CC: libc-alpha@sourceware.org Subject: Re: Add macros for diagnostic control, use them in locale/weightwc.h References: <546F79BB.80604@cs.ucla.edu> <546F8FA5.2050702@cs.ucla.edu> In-Reply-To: Joseph Myers wrote: > it's warning about str[1] for an array > wint_t str[1] for which only str[0] is valid and only str[0] exists to be > initialized (but the - unreachable - code is, after propagating some > constants, accessing str[1]). Yeouch, GCC is even more confused than I thought. Instead of masking the GCC bug, how about changing the libc source slightly so that the bug isn't tickled? The attached patch does that, and this fixes the bug for me (x86-64, both GCC 4.9.2 and GCC 4.8.3) without having to fiddle with any pragmas. As a bonus this patch seems to make the resulting machine code slightly more efficient; it's smaller, anyway. We did this sort of thing with gnulib etc. too. If memory serves, occasionally the buggy warnings were signs of other trouble within GCC, so it wasn't unreasonable to change the code to pacify the compiler. I do try to file GCC bug reports for this sort of thing but I'm not perfect in that regard. From 7c16bdc58c74e3515d8d71e5e006005566e5a32a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 21 Nov 2014 20:57:58 -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 | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c75dab7..3c7b9e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-11-21 Paul Eggert + + 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-21 Roland McGrath * nptl/pthread_create.c (__pthread_create_2_1): Set diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c index db6d9d7..c1d8b69 100644 --- a/posix/fnmatch_loop.c +++ b/posix/fnmatch_loop.c @@ -343,7 +343,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used) #ifdef _LIBC else if (c == L('[') && *p == L('=')) { - UCHAR str[1]; + UCHAR str; uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); const CHAR *startp = p; @@ -355,7 +355,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 +368,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 +383,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