All of lore.kernel.org
 help / color / mirror / Atom feed
From: David <dllorens@lsi.uji.es>
To: linux-kernel@vger.kernel.org
Subject: Posible bug in gcc
Date: Mon, 26 Feb 2001 17:30:01 +0100	[thread overview]
Message-ID: <3A9A8489.224CF54C@inf.uji.es> (raw)

[-- 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);
}


             reply	other threads:[~2001-02-26 16:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-26 16:30 David [this message]
2001-02-26 17:15 ` Posible bug in gcc 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3A9A8489.224CF54C@inf.uji.es \
    --to=dllorens@lsi.uji.es \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.