diff mbox

Get rid of array-bounds warning in __kernel_rem_pio2[f] with gcc 6.1 -O3.

Message ID 577E1156.2030604@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Stefan Liebler July 7, 2016, 8:22 a.m. UTC
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.
Afterwards glibc builds/tests fine with gcc 6.1 and -O3.

Okay to commit?
Before or after release?

Bye
Stefan

ChangeLog:

	* sysdeps/ieee754/dbl-64/k_rem_pio2.c (__kernel_rem_pio2):
	Add test to ensure that array-index is >= 0.
	* sysdeps/ieee754/flt-32/k_rem_pio2f.c (__kernel_rem_pio2f):
	Likewise.

Comments

Stefan Liebler July 13, 2016, 10:25 a.m. UTC | #1
PING

On 07/07/2016 10:22 AM, 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.
> Afterwards glibc builds/tests fine with gcc 6.1 and -O3.
>
> Okay to commit?
> Before or after release?
>
> Bye
> Stefan
>
> ChangeLog:
>
>      * sysdeps/ieee754/dbl-64/k_rem_pio2.c (__kernel_rem_pio2):
>      Add test to ensure that array-index is >= 0.
>      * sysdeps/ieee754/flt-32/k_rem_pio2f.c (__kernel_rem_pio2f):
>      Likewise.
Stefan Liebler July 20, 2016, 2:03 p.m. UTC | #2
PING

On 07/13/2016 12:25 PM, Stefan Liebler wrote:
> PING
>
> On 07/07/2016 10:22 AM, 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.
>> Afterwards glibc builds/tests fine with gcc 6.1 and -O3.
>>
>> Okay to commit?
>> Before or after release?
>>
>> Bye
>> Stefan
>>
>> ChangeLog:
>>
>>      * sysdeps/ieee754/dbl-64/k_rem_pio2.c (__kernel_rem_pio2):
>>      Add test to ensure that array-index is >= 0.
>>      * sysdeps/ieee754/flt-32/k_rem_pio2f.c (__kernel_rem_pio2f):
>>      Likewise.
>
>
Joseph Myers July 20, 2016, 4:33 p.m. UTC | #3
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.
diff mbox

Patch

diff --git a/sysdeps/ieee754/dbl-64/k_rem_pio2.c b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
index e58c9e8..4fe14de 100644
--- a/sysdeps/ieee754/dbl-64/k_rem_pio2.c
+++ b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
@@ -251,7 +251,7 @@  recompute:
 	j |= iq[i];
       if (j == 0)      /* need recomputation */
 	{
-	  for (k = 1; iq[jk - k] == 0; k++)
+	  for (k = 1; k <= jk && iq[jk - k] == 0; k++)
 	    ;                               /* k = no. of terms needed */
 
 	  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..805f487 100644
--- a/sysdeps/ieee754/flt-32/k_rem_pio2f.c
+++ b/sysdeps/ieee754/flt-32/k_rem_pio2f.c
@@ -122,7 +122,8 @@  recompute:
 	    j = 0;
 	    for (i=jz-1;i>=jk;i--) j |= iq[i];
 	    if(j==0) { /* need recomputation */
-		for(k=1;iq[jk-k]==0;k++);   /* k = no. of terms needed */
+		for (k = 1; k <= jk && iq[jk - k] == 0; k++)
+		  ;    /* k = no. of terms needed */
 
 		for(i=jz+1;i<=jz+k;i++) {   /* add q[jz+1] to q[jz+k] */
 		    f[jx+i] = (float) ipio2[jv+i];