Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* horrible "cc -O" bug (DU 3.2c)
@ 1997-05-09  4:00 Mark Bartelt
  1997-05-09  4:00 ` Jonathan Rozes
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Mark Bartelt @ 1997-05-09  4:00 UTC (permalink / raw)



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 <stdio.h>

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



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~1997-05-13  4:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-05-09  4:00 horrible "cc -O" bug (DU 3.2c) Mark Bartelt
1997-05-09  4:00 ` Jonathan Rozes
1997-05-09  4:00 ` John Hascall
1997-05-10  4:00   ` Gerald Feldman
1997-05-11  4:00   ` Roy Smith
1997-05-11  4:00     ` Michael C. Grant
1997-05-11  4:00     ` Gerald A. Feldman
1997-05-11  4:00       ` Roy Smith
1997-05-12  4:00         ` Jeff Sullivan USG
1997-05-12  4:00           ` Gerald A. Feldman
1997-05-12  4:00         ` Mark Bartelt
1997-05-12  4:00           ` Andy Isaacson
1997-05-12  4:00             ` John Reinitz
1997-05-13  4:00             ` Mark Bartelt
1997-05-12  4:00       ` Bob Vickers
1997-05-12  4:00       ` Peter Kocourek
1997-05-12  4:00       ` Jeff Sullivan USG
     [not found] ` <5l7hap$7la@usenet.pa.dec.com>
1997-05-12  4:00   ` Gerald A. Feldman

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