From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075316706364.tru64-unix-managers.marc@archive.invalid> From: Mattias Ohlsson Date: Thu, 05 Jan 1995 15:28:12 +0000 To: tru64-unix-managers Subject: Another "cc -O2" compiler bug? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075316706364 Consider this small piece of code: ------------------ #include #include 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 ---------------------------------