linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* 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

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).