c/5926: gcc 3.0.3 generates incorrect code with -O3 option
gbv@oxixares.com
gbv@oxixares.com
Tue Mar 12 12:06:00 GMT 2002
>Number: 5926
>Category: c
>Synopsis: gcc 3.0.3 generates incorrect code with -O3 option
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Mar 12 12:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Guillermo Ballester Valor
>Release: 3.0.3
>Organization:
>Environment:
System: Linux mozart 2.2.19 #2 Sat Jun 2 21:32:31 CEST 2001 i586 unknown
Architecture: i586
host: i586-pc-linux-gnu
build: i586-pc-linux-gnu
target: i586-pc-linux-gnu
configured with: ./configure
>Description:
I've detected a problem when updated from gcc 2.95.2 . A result was different depending on the
order of a line of code were written, without aparent cause, when using -O3
>How-To-Repeat:
See the problem compiling the following code with -O3 option. The two routines are the same but
a code of line changed. I think both results would be the same but I get different resuts.
-----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
size_t last_nsize=0;
#define BITS_PER_LIMB 32
unsigned long Y_MASQ,Y_LIMB,Y_MAX,Y_BITS;
double Y_TINV;
int bugy_routine(size_t n1, size_t n2)
{
size_t n,nsize,needed=0,i;
nsize= n1 + n2;
/*See whether all the initialization work con be avoided */
needed=(nsize*BITS_PER_LIMB);
Y_BITS = (unsigned long)((double)24.00 - 0.5*log((double)needed));
Y_MASQ=((1U<<Y_BITS)-1L);
Y_LIMB=(1U<<Y_BITS);
Y_MAX=(1U<<(Y_BITS-1));
Y_TINV=1.0/(double)Y_LIMB;
needed=(needed-1)/(size_t)Y_BITS+3; /****** LINE CHANGED *******/
return needed;
}
int nobugy_routine(size_t n1, size_t n2)
{
size_t n,nsize,needed=0,i;
int save;
nsize= n1 + n2;
/*See whether all the initialization work con be avoided */
needed=(nsize*BITS_PER_LIMB);
Y_BITS = (unsigned long)((double)24.00 - 0.5*log((double)needed));
needed=(needed-1)/(size_t)Y_BITS+3; /****** LINE CHANGED *******/
Y_MASQ=((1U<<Y_BITS)-1L);
Y_LIMB=(1U<<Y_BITS);
Y_MAX=(1U<<(Y_BITS-1));
Y_TINV=1.0/(double)Y_LIMB;
return needed;
}
int main(int argc, char **argv)
{
size_t n1=500, n2=500, res1, res2;
res1=nobugy_routine(n1,n2);
printf("Results of no bugy routine %i\n",res1);
res2=bugy_routine(n1,n2);
printf("Results of bugy routine %i\n",res2);
}
------------------------------------------
>Fix:
I don't know
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list