public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: gbv@oxixares.com
To: gcc-gnats@gcc.gnu.org
Subject: c/5926: gcc 3.0.3 generates incorrect code with -O3 option
Date: Tue, 12 Mar 2002 12:06:00 -0000	[thread overview]
Message-ID: <200203122003.g2CK3Jf01400@mozart.oxixares.com> (raw)


>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:


             reply	other threads:[~2002-03-12 20:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-12 12:06 gbv [this message]
2002-03-18 15:47 jakub
2002-03-18 22:26 Guillermo Ballester Valor
2002-04-29  0:26 gbv
2003-01-01 19:08 neroden

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=200203122003.g2CK3Jf01400@mozart.oxixares.com \
    --to=gbv@oxixares.com \
    --cc=gcc-gnats@gcc.gnu.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).