From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,ae6d7754224e7cfb X-Google-Attributes: gid1164f8,public X-Google-Thread: fee84,ae6d7754224e7cfb X-Google-Attributes: gidfee84,public From: mark@cita.toronto.edu (Mark Bartelt) Subject: horrible "cc -O" bug (DU 3.2c) Date: 1997/05/09 Message-ID: #1/1 X-Deja-AN: 240575948 Sender: nntp@utcc.utoronto.ca (News) X-Nntp-Posting-Host: rorqual.cita.utoronto.ca Organization: Canadian Institute for Theoretical Astrophysics Reply-To: mark@cita.utoronto.ca Newsgroups: comp.unix.osf.osf1,comp.sys.dec Someone just called my attention to a really disturbing bug in DEC's C compiler. It seems that if a program is compiled with "-O", then evaluation of "expr1 && expr2" is botched: Even when expr1 evaluates to 0, expr2 gets evaluated anyway! The implications of this bug are rather staggering; for example, what if expr2 has side-effects? Gack. The bug seems to appear only when "-O" is used. Here's a short example program. It generates a floating-point exception when compiled with "-O". (It shouldn't, since the expression to the right of the "&&" should never be evaluated.) We're running version 3.2c of Digital UNIX. Can anyone tell me whether this bug got fixed in 4.0? ----------------------------------------------------------- moose> cat xx.c #include static double test(int flag, double x, double y) { printf("flag: %d x: %.4g y: %.4g\n", flag, x, y); if ( flag && 1/x > y ) x = 0; return(x); } int main() { (void)test(0, 0.0, 1.0); } moose> moose> cc -o xx xx.c moose> xx flag: 0 x: 0 y: 1 moose> moose> cc -O -o xx xx.c moose> xx flag: 0 x: 0 y: 1 Floating exception - core dumped moose> ----------------------------------------------------------- Mark Bartelt 416/978-5619 Canadian Institute for mark@cita.utoronto.ca Theoretical Astrophysics http://www.cita.utoronto.ca/~mark "Nur eine Waffel taugt!" -- Parsifal, in an Eggo commercial