Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: mark@cita.toronto.edu (Mark Bartelt)
Subject: horrible "cc -O" bug (DU 3.2c)
Date: 1997/05/09	[thread overview]
Message-ID: <E9wuF5.8JE@utcc.utoronto.ca> (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



             reply	other threads:[~1997-05-09  4:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-09  4:00 Mark Bartelt [this message]
1997-05-09  4:00 ` horrible "cc -O" bug (DU 3.2c) 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         ` 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         ` Jeff Sullivan USG
1997-05-12  4:00           ` Gerald A. Feldman
1997-05-12  4:00       ` Bob Vickers
1997-05-12  4:00       ` Jeff Sullivan USG
1997-05-12  4:00       ` Peter Kocourek
     [not found] ` <5l7hap$7la@usenet.pa.dec.com>
1997-05-12  4:00   ` Gerald A. Feldman
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