This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Unreachable statmnt reached using gcc2.95 under Linux-Mdk
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Unreachable statmnt reached using gcc2.95 under Linux-Mdk
- From: Remi Dessarce <Remi dot Dessarce at imag dot fr>
- Date: Mon, 17 Jan 2000 13:23:30 +0100
Hi,
this is a try to report a bug.
1) gcc -v gives :
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
2) Source file is main.c (attached)
3) Compilation commands used :
a) gcc main.c -o gcctest
b) gcc -O main.c -o gccOtest
c) gcc -O2 main.c -o gccO2test
4) Platform :
intel-i686 running under Linux-Mandrake 2.2.9-27mdk
5) Installation :
- gcc-cpp
- gcc
- gcc-c++
- gcc-g77
all from Mandrake rpm's version 2.95.2-3
6) Problems description :
The variable 'result' used in the program is getting the value
of 2 if and only if a test evaluates once to true and,
just after, once to false.
a) The executable 'gccOtest' (gcc -O) gives the value
of 2 to 'result'.
The other two ('gcctest' and 'gccO2test') don't have
the same problem giving a value of 1 to 'result'.
b) If the final 'printf' statement is put just before the three
last tests then the command 'gcc -O2 main.c -o gccO2test'
produces an executable getting back to weird output (result=2).
The only 'correct' version being the one with no optimization
at all.
Of course, I know that the comparison between floating-point values
is not suitable in general. Here, the problem is that the same test
(in source code) evaluates differently when called twice
consecutively (still in source file).
7) The attached files 'main.i.gz', 'main.O.i.gz' and 'main.O2.i.gz'
where produced by :
> gcc -g -O2 -save-temps main.c
> mv main.i main.O2.i
> gzip -9 main.O2.i
> gcc -g -O -save-temps main.c
> mv main.i main.O.i
> gzip -9 main.O.i
> gcc -g -save-temps main.c
> gzip -9 main.i
Please, feel free to ask me more information if needed.
I hope this bug-report is of interest for someone
and, if not, to have not make anybody waste too much time.
Thx in advance to send me directly any information
concerning this problem.
--
___________________________________________________________
Remi DESSARCE (Remi.Dessarce@imag.fr)
S.A. UNIVAL & L.M.C./I.M.A.G. Grenoble, France
Tel: +33 (0)4.76.51.49.94 Fax: +33 (0)4.76.63.12.63
main.O2.i.gz
main.O.i.gz
main.i.gz
#include <stdlib.h>
#include <stdio.h>
#define N 32
int main (int argc, char *argv[])
{
float t[N], sumt1, sumt2;
int i, result;
/* Initialize some floating-point values in array t */
for(i=0; (i<N); i++)
t[i]=1.0/2.1;
/* Compute the sum of the t[i]'s */
sumt1=0.0;
for(i=0; (i<N); i++)
sumt1+=(t[i]);
result=0;
sumt2=0.0;
/* Same computation as the previous loop except for a few tests */
for(i=0; (i<N) && (result==0); i++)
{
sumt2+=(t[i]);
if(sumt2>=sumt1)
{
result=1;
}
else
{
if(sumt2>=sumt1)
{
result=2; /* This statement should never be reached */
}
}
}
if(sumt2>=sumt1) printf("sumt2>=sumt1\n");
if(sumt2==sumt1) printf("sumt2==sumt1\n");
if(sumt2< sumt1) printf("sumt2< sumt1\n");
printf("result=%d, i=%d\n",result,i);
return(0);
}/*main*/