* Posible bug in gcc
@ 2001-02-26 16:30 David
2001-02-26 17:15 ` Alan Cox
2001-02-26 22:30 ` J . A . Magallon
0 siblings, 2 replies; 10+ messages in thread
From: David @ 2001-02-26 16:30 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 858 bytes --]
I hope you will find this information usefull.
I am not in the linux-kernel list so, if posible, I would like to be
personally CC'ed the answers/comments sent to the list in response to
this posting.
I think I heve found a bug in gcc. I have tried both egcs 1.1.2 (gcc
2.91.66) and gcc 2.95.2 versions.
I am attaching you a simplified test program ('bug.c', a really simple
program).
To generate the faulty program from correct code compile as:
gcc -O2 -o bug bug.c
You can generate good code in two ways:
1. Compiling with:
gcc -fno-strength-reduce -O2 -o bug bug.c
So the problem is with the option -fstrength-reduce which is
active with the common '-O2' optimization option.
2. Uncomment the printf at line 34. Bugs are surprising.
I have also sent the bug report to the gcc maintainers.
Is it really a bug?
Thank you,
David Llorens.
[-- Attachment #2: bug.c --]
[-- Type: text/plain, Size: 862 bytes --]
/*
#include <stdio.h>
*/
#define SMALL_N 2
#define NUM_ELEM 4
int main(void)
{
int listElem[NUM_ELEM]={30,2,10,5};
int listSmall[SMALL_N];
int i, j;
int posGreatest=-1, greatest=-1;
for (i=0; i<SMALL_N; i++) {
listSmall[i] = listElem[i];
if (listElem[i] > greatest) {
posGreatest = i;
greatest = listElem[i];
}
}
for (i=SMALL_N; i<NUM_ELEM; i++) {
if (listElem[i] < greatest) {
listSmall[posGreatest] = listElem[i];
posGreatest = 0;
greatest = listSmall[0];
for (j=1; j<SMALL_N; j++)
if (listSmall[j] > greatest) {
posGreatest = j;
greatest = listSmall[j];
}
/*
printf("%d\n", posGreatest);
*/
}
}
printf("Correct output: 5 2\n");
printf("GCC output: ");
for (i=0; i<SMALL_N; i++) printf(" %.1d", listSmall[i]);
printf("\n");
return (1);
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 16:30 Posible bug in gcc David
@ 2001-02-26 17:15 ` Alan Cox
2001-02-26 17:33 ` Jakub Jelinek
2001-02-26 22:30 ` J . A . Magallon
1 sibling, 1 reply; 10+ messages in thread
From: Alan Cox @ 2001-02-26 17:15 UTC (permalink / raw)
To: David; +Cc: linux-kernel
> I think I heve found a bug in gcc. I have tried both egcs 1.1.2 (gcc
> 2.91.66) and gcc 2.95.2 versions.
>
> I am attaching you a simplified test program ('bug.c', a really simple
> program).
Well gcc-bugs would be the better place to send it but this is a known problem
fixed in CVS gcc 2.95.3, CVS gcc 3.0 branch and gcc 2.96 (unofficial, Red Hat)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 17:15 ` Alan Cox
@ 2001-02-26 17:33 ` Jakub Jelinek
2001-02-26 18:02 ` Alan Cox
2001-02-26 20:53 ` David Relson
0 siblings, 2 replies; 10+ messages in thread
From: Jakub Jelinek @ 2001-02-26 17:33 UTC (permalink / raw)
To: Alan Cox; +Cc: David, linux-kernel
On Mon, Feb 26, 2001 at 05:15:28PM +0000, Alan Cox wrote:
> > I think I heve found a bug in gcc. I have tried both egcs 1.1.2 (gcc
> > 2.91.66) and gcc 2.95.2 versions.
> >
> > I am attaching you a simplified test program ('bug.c', a really simple
> > program).
>
> Well gcc-bugs would be the better place to send it but this is a known problem
> fixed in CVS gcc 2.95.3, CVS gcc 3.0 branch and gcc 2.96 (unofficial, Red Hat)
I'm not sure if it is known, at least not known to me, but definitely not
fixed in any of gcc 2.95.2, CVS gcc 3.0 branch, CVS gcc 3.1 head, gcc 2.96-RH.
Jakub
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 17:33 ` Jakub Jelinek
@ 2001-02-26 18:02 ` Alan Cox
2001-02-26 18:02 ` Richard B. Johnson
2001-02-26 21:03 ` J . A . Magallon
2001-02-26 20:53 ` David Relson
1 sibling, 2 replies; 10+ messages in thread
From: Alan Cox @ 2001-02-26 18:02 UTC (permalink / raw)
To: jakub; +Cc: Alan Cox, David, linux-kernel
> > Well gcc-bugs would be the better place to send it but this is a known problem
> > fixed in CVS gcc 2.95.3, CVS gcc 3.0 branch and gcc 2.96 (unofficial, Red Hat)
>
> I'm not sure if it is known, at least not known to me, but definitely not
> fixed in any of gcc 2.95.2, CVS gcc 3.0 branch, CVS gcc 3.1 head, gcc 2.96-RH.
Sorry my error for assuming it was the exsting known strength reduce bug
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 18:02 ` Alan Cox
@ 2001-02-26 18:02 ` Richard B. Johnson
2001-02-27 19:50 ` Ville Herva
2001-02-26 21:03 ` J . A . Magallon
1 sibling, 1 reply; 10+ messages in thread
From: Richard B. Johnson @ 2001-02-26 18:02 UTC (permalink / raw)
To: Alan Cox; +Cc: jakub, David, linux-kernel
On Mon, 26 Feb 2001, Alan Cox wrote:
> > > Well gcc-bugs would be the better place to send it but this is a known problem
> > > fixed in CVS gcc 2.95.3, CVS gcc 3.0 branch and gcc 2.96 (unofficial, Red Hat)
> >
> > I'm not sure if it is known, at least not known to me, but definitely not
> > fixed in any of gcc 2.95.2, CVS gcc 3.0 branch, CVS gcc 3.1 head, gcc 2.96-RH.
>
> Sorry my error for assuming it was the exsting known strength reduce bug
>
Script started on Mon Feb 26 12:54:20 2001
# gcc -o xxx bug.c
# ./xxx
Correct output: 5 2
GCC output: 5 2
# gcc --version
egcs-2.91.66
# gcc -O2 -o xxx bug.c
# ./xxx
Correct output: 5 2
GCC output: 10 5
# exit
exit
Script done on Mon Feb 26 12:55:21 2001
Definitely has something to do with broken optimization. No optimization,
no bug, turn on '-O2' and you have the bug.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).
"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 17:33 ` Jakub Jelinek
2001-02-26 18:02 ` Alan Cox
@ 2001-02-26 20:53 ` David Relson
1 sibling, 0 replies; 10+ messages in thread
From: David Relson @ 2001-02-26 20:53 UTC (permalink / raw)
To: Alan Cox; +Cc: jakub, Alan Cox, David, linux-kernel
At 01:02 PM 2/26/01, Alan Cox wrote:
> > > Well gcc-bugs would be the better place to send it but this is a
> known problem
> > > fixed in CVS gcc 2.95.3, CVS gcc 3.0 branch and gcc 2.96 (unofficial,
> Red Hat)
> >
> > I'm not sure if it is known, at least not known to me, but definitely not
> > fixed in any of gcc 2.95.2, CVS gcc 3.0 branch, CVS gcc 3.1 head, gcc
> 2.96-RH.
>
>Sorry my error for assuming it was the exsting known strength reduce bug
It's broken in my copy of gcc.2.95.3 ...
David
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 18:02 ` Alan Cox
2001-02-26 18:02 ` Richard B. Johnson
@ 2001-02-26 21:03 ` J . A . Magallon
1 sibling, 0 replies; 10+ messages in thread
From: J . A . Magallon @ 2001-02-26 21:03 UTC (permalink / raw)
To: Alan Cox; +Cc: jakub, Alan Cox, David, linux-kernel
On 02.26 Alan Cox wrote:
Also fails in gcc-2.96-0.38mdk (Mandrake Cooker):
rpm -q --changelog gcc
* Sat Feb 17 2001 Chmouel Boudjnah <chmouel@mandrakesoft.com> 2.96-0.38mdk
- exit 0 if [ $1 = 0 ] if we are in %postun (to don't screwd up the
alternatives).
* Thu Feb 15 2001 David BAUDENS <baudens@mandrakesoft.com> 2.96-0.37mdk
- Fix build on PPC :)
* Thu Feb 15 2001 Chmouel Boudjnah <chmouel@mandrakesoft.com> 2.96-0.36mdk
- Break build on PPC ;).
- Red Hat patches, Jakub Jelinek (rel74) 5 new patches :
--
J.A. Magallon $> cd pub
mailto:jamagallon@able.es $> more beer
Linux werewolf 2.4.2-ac4 #2 SMP Mon Feb 26 00:21:23 CET 2001 i686
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 16:30 Posible bug in gcc David
2001-02-26 17:15 ` Alan Cox
@ 2001-02-26 22:30 ` J . A . Magallon
2001-02-27 10:56 ` Erik Mouw
1 sibling, 1 reply; 10+ messages in thread
From: J . A . Magallon @ 2001-02-26 22:30 UTC (permalink / raw)
To: David; +Cc: linux-kernel
On 02.26 David wrote:
> I hope you will find this information usefull.
>
> I am not in the linux-kernel list so, if posible, I would like to be
> personally CC'ed the answers/comments sent to the list in response to
> this posting.
>
> I think I heve found a bug in gcc. I have tried both egcs 1.1.2 (gcc
> 2.91.66) and gcc 2.95.2 versions.
>
gcc2.95.2 is sane in irix6.2, irix6.5 and solaris7sparc.
The optimizer is not in the common front-end ?
--
J.A. Magallon $> cd pub
mailto:jamagallon@able.es $> more beer
Linux werewolf 2.4.2-ac4 #2 SMP Mon Feb 26 00:21:23 CET 2001 i686
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 22:30 ` J . A . Magallon
@ 2001-02-27 10:56 ` Erik Mouw
0 siblings, 0 replies; 10+ messages in thread
From: Erik Mouw @ 2001-02-27 10:56 UTC (permalink / raw)
To: J . A . Magallon; +Cc: David, linux-kernel
On Mon, Feb 26, 2001 at 11:30:13PM +0100, J . A . Magallon wrote:
> On 02.26 David wrote:
> > I think I heve found a bug in gcc. I have tried both egcs 1.1.2 (gcc
> > 2.91.66) and gcc 2.95.2 versions.
>
> gcc2.95.2 is sane in irix6.2, irix6.5 and solaris7sparc.
>
> The optimizer is not in the common front-end ?
Yes and no. There is some common code in the optimiser, but each target
has its own optimisation tricks for which the code is not shared with
other targets.
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Posible bug in gcc
2001-02-26 18:02 ` Richard B. Johnson
@ 2001-02-27 19:50 ` Ville Herva
0 siblings, 0 replies; 10+ messages in thread
From: Ville Herva @ 2001-02-27 19:50 UTC (permalink / raw)
To: linux-kernel
On Mon, Feb 26, 2001 at 01:02:45PM -0500, you [Richard B. Johnson] claimed:
>
> Script started on Mon Feb 26 12:54:20 2001
> # gcc -o xxx bug.c
> # ./xxx
> Correct output: 5 2
> GCC output: 5 2
> # gcc --version
> egcs-2.91.66
> # gcc -O2 -o xxx bug.c
> # ./xxx
> Correct output: 5 2
> GCC output: 10 5
> # exit
> exit
Funny:
vherva@babbage:/tmp>/usr/bin/gcc c.c -o c; ./c ; /usr/bin/gcc --version
Correct output: 5 2
GCC output: 5 2
2.96
vherva@babbage:/tmp>/usr/bin/gcc -O2 c.c -o c; ./c ; /usr/bin/gcc --version
Correct output: 5 2
GCC output: 10 5
2.96
vherva@babbage:/tmp>/usr/bin/gcc -O6 c.c -o c; ./c ; /usr/bin/gcc --version
Correct output: 5 2
GCC output: 10 5
2.96
vherva@babbage:/tmp>rpm -q gcc
gcc-2.96-74
vherva@babbage:/tmp>kgcc c.c -o c; ./c ; kgcc --version
Correct output: 5 2
GCC output: 5 2
egcs-2.91.66
vherva@babbage:/tmp>kgcc c.c -O2 -o c; ./c ; kgcc --version
Correct output: 5 2
GCC output: 10 5
egcs-2.91.66
vherva@babbage:/tmp>kgcc c.c -O6 -o c; ./c ; kgcc --version
Correct output: 5 2
GCC output: 10 5
egcs-2.91.66
vherva@babbage:/tmp>rpm -q kgcc
kgcc-1.1.2-40
vherva@babbage:/tmp>/usr/local/bin/gcc c.c -o c; ./c ;/usr/local/bin/gcc --version
Correct output: 5 2
GCC output: 5 2
pgcc-2.95.1
vherva@babbage:/tmp>/usr/local/bin/gcc c.c -O2 -o c; ./c ;/usr/local/bin/gcc --version
Correct output: 5 2
GCC output: 5 2
pgcc-2.95.1
vherva@babbage:/tmp>/usr/local/bin/gcc c.c -O6 -o c; ./c ;/usr/local/bin/gcc --version
Correct output: 5 2
GCC output: 5 2
pgcc-2.95.1
I guess pgcc is not that buggy EVERY time. (Sorry for the off topic post, I
couldn't resist.)
-- v --
v@iki.fi
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2001-02-27 19:51 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-26 16:30 Posible bug in gcc David
2001-02-26 17:15 ` Alan Cox
2001-02-26 17:33 ` Jakub Jelinek
2001-02-26 18:02 ` Alan Cox
2001-02-26 18:02 ` Richard B. Johnson
2001-02-27 19:50 ` Ville Herva
2001-02-26 21:03 ` J . A . Magallon
2001-02-26 20:53 ` David Relson
2001-02-26 22:30 ` J . A . Magallon
2001-02-27 10:56 ` Erik Mouw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).