tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* Another "cc -O2" compiler bug?
@ 1995-01-05 15:28 Mattias Ohlsson
  0 siblings, 0 replies; only message in thread
From: Mattias Ohlsson @ 1995-01-05 15:28 UTC (permalink / raw)
  To: tru64-unix-managers


Consider this small piece of code:

------------------
#include <stdio.h>
#include <math.h>

void tmp( double );

void main()
{
  double x;

  x = 1.0;
  tmp(x);
}

void tmp( double xx )
{
  double fkn1, fkn2, arg, aux1, aux2;
  
  aux2 = xx;
  aux1 = 1.0;

  /** original definition - gives the inverse of the correct thing **/
  fkn1 = exp(-aux1 * aux2);

  /** alternative definition - gives the correct result **/
  arg = aux1 * aux2;
  fkn2 = exp(-arg);

  printf("%f  %f  %f  %f\n", xx, fkn1, fkn2, fkn1 * fkn2);
}
------------------

If I compile with default optimization I get the following 
correct result:

>> cc -o bug bug.c -lm
>> bug
1.000000  0.367879  0.367879  0.135335
>>

If I however compile with -O2 optimization, bad things happen.

>> cc -O2 -o bug bug.c -lm
>> bug
1.000000  2.718282  0.367879  1.000000
>>

For some strange reason the compiler forgets about the minus
sign in front of aux1.

fkn1 = exp(-aux1 * aux2);
-----------^

Can anyone verify this? If so, where is the patch?

My system:

>> uname -a
OSF1 selma.thep.lu.se V3.0 347 alpha


/Mattias

---------------------------------
Mattias Ohlsson
Department of Theoretical Physics
Lund University
Sweden
---------------------------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-01-05 15:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-01-05 15:28 Another "cc -O2" compiler bug? Mattias Ohlsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox