From patchwork Mon Jul 25 15:55:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 13977 Received: (qmail 104792 invoked by alias); 25 Jul 2016 15:55:49 -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 104783 invoked by uid 89); 25 Jul 2016 15:55:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=jkk, Myers X-HELO: plane.gmane.org To: libc-alpha@sourceware.org From: Stefan Liebler Subject: Re: [PATCH] Get rid of array-bounds warning in __kernel_rem_pio2[f] with gcc 6.1 -O3. Date: Mon, 25 Jul 2016 17:55:36 +0200 Lines: 112 Message-ID: References: <577E1156.2030604@linux.vnet.ibm.com> Mime-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: On 07/20/2016 06:33 PM, Joseph Myers wrote: > On Thu, 7 Jul 2016, Stefan Liebler wrote: > >> Hi, >> >> while testing, I've got the following werror on s390x when build with gcc 6.1 >> (or current gcc head) and -O3: >> ../sysdeps/ieee754/dbl-64/k_rem_pio2.c: In function ‘__kernel_rem_pio2’: >> ../sysdeps/ieee754/dbl-64/k_rem_pio2.c:254:18: error: array subscript is below >> array bounds [-Werror=array-bounds] >> for (k = 1; iq[jk - k] == 0; k++) >> ~~^~~~~~~~ >> >> I get the same error with sysdeps/ieee754/flt-32/k_rem_pio2f.c. >> >> Does anybody else get this warning on another architecture, too? >> >> This patch adds a check so that the index is always >= 0. > > Such an unnecessary check is not how we deal with bogus warnings. > Rather, use the DIAG_*_NEEDS_COMMENT macros from include/libc-internal.h, > with a detailed comment explaining what the warning is and why it is a > false positive. > Sorry for the delay. Here is the updated patch with DIAG_* macros. Is this okay? Bye Stefan ChangeLog: ChangeLog: * sysdeps/ieee754/dbl-64/k_rem_pio2.c (__kernel_rem_pio2): Use DIAG_*_NEEDS_COMMENT macro to get rid of array-bounds warning. * sysdeps/ieee754/flt-32/k_rem_pio2f.c (__kernel_rem_pio2f): Likewise. diff --git a/sysdeps/ieee754/dbl-64/k_rem_pio2.c b/sysdeps/ieee754/dbl-64/k_rem_pio2.c index e58c9e8..4fa05b9 100644 --- a/sysdeps/ieee754/dbl-64/k_rem_pio2.c +++ b/sysdeps/ieee754/dbl-64/k_rem_pio2.c @@ -132,6 +132,7 @@ static char rcsid[] = "$NetBSD: k_rem_pio2.c,v 1.7 1995/05/10 20:46:25 jtc Exp $ #include #include +#include static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ @@ -251,8 +252,16 @@ recompute: j |= iq[i]; if (j == 0) /* need recomputation */ { + /* On s390x gcc 6.1 -O3 produces the warning "array subscript is below + array bounds [-Werror=array-bounds]". Only __ieee754_rem_pio2l() + calls __kernel_rem_pio2f() for normal numbers and |x| > 3pi/4. Thus + x can't be zero and ipio2 is not zero, too. Thus not all iq[] + values can't be zero. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (6.1, "-Warray-bounds"); for (k = 1; iq[jk - k] == 0; k++) ; /* k = no. of terms needed */ + DIAG_POP_NEEDS_COMMENT; for (i = jz + 1; i <= jz + k; i++) /* add q[jz+1] to q[jz+k] */ { diff --git a/sysdeps/ieee754/flt-32/k_rem_pio2f.c b/sysdeps/ieee754/flt-32/k_rem_pio2f.c index 392afdb..83d3214 100644 --- a/sysdeps/ieee754/flt-32/k_rem_pio2f.c +++ b/sysdeps/ieee754/flt-32/k_rem_pio2f.c @@ -19,6 +19,7 @@ static char rcsid[] = "$NetBSD: k_rem_pio2f.c,v 1.4 1995/05/10 20:46:28 jtc Exp #include #include +#include /* In the float version, the input parameter x contains 8 bit integers, not 24 bit integers. 113 bit precision is not supported. */ @@ -122,7 +123,15 @@ recompute: j = 0; for (i=jz-1;i>=jk;i--) j |= iq[i]; if(j==0) { /* need recomputation */ + /* On s390x gcc 6.1 -O3 produces the warning "array subscript is + below array bounds [-Werror=array-bounds]". Only + __ieee754_rem_pio2f() calls __kernel_rem_pio2f() for normal + numbers and |x| ~> 2^7*(pi/2). Thus x can't be zero and ipio2 + is not zero, too. Thus not all iq[] values can't be zero. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT (6.1, "-Warray-bounds"); for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ + DIAG_POP_NEEDS_COMMENT; for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ f[jx+i] = (float) ipio2[jv+i];