From: Mattias Ohlsson <mattias () thep ! lu ! se>
To: tru64-unix-managers
Subject: Another "cc -O2" compiler bug?
Date: Thu, 05 Jan 1995 15:28:12 +0000 [thread overview]
Message-ID: <96075316706364.tru64-unix-managers.marc@archive.invalid> (raw)
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
---------------------------------
reply other threads:[~1995-01-05 15:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox