Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: john@iastate.edu (John Hascall)
Subject: Re: horrible "cc -O" bug (DU 3.2c)
Date: 1997/05/09	[thread overview]
Message-ID: <5kvqsu$18d$1@news.iastate.edu> (raw)
In-Reply-To: E9wuF5.8JE@utcc.utoronto.ca


Mark Bartelt <mark@cita.utoronto.ca> wrote:
}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.)

    Gack!  Here's the code w/o and with -O:

#    6	  if ( flag && 1/x > y ) x = 0;

     ldl     $1,   16($sp)                 ldl     $1,   48($sp)
     beq     $1,   $32                     ldit    $f10, 1.0000000000000000e+00
     ldit    $f10, 1.0000000000000000e+00  divt    $f10, $f17, $f11
     ldt     $f11, 24($sp)                 ldt     $f12, 64($sp)
     divt    $f10, $f11, $f12              cmptlt  $f12, $f11, $f13
     ldt     $f13, 32($sp)                 cpys    $f17, $f17, $f14
     cmptlt  $f13, $f12, $f14              fcmovne $f13, $f31, $f14
     fbeq    $f14, $32                     stq     $1,   32($sp)
     stt     $f31, 24($sp)                 ldt     $f15, 32($sp)
$32:                                       cpys    $f14, $f14, $f0
                                           fcmoveq $f15, $f17, $f0

   Obviously they are trying to use conditional
   moves to avoid branches - but this is really
   wrong...

John
-- 
John Hascall, Software Engr.        Shut up, be happy.  The conveniences you
ISU Computation Center              demanded are now mandatory. -Jello Biafra
mailto:john@iastate.edu
http://www.cc.iastate.edu/staff/systems/john/welcome.html  <-- the usual crud



  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 horrible "cc -O" bug (DU 3.2c) Mark Bartelt
1997-05-09  4:00 ` John Hascall [this message]
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       ` Jeff Sullivan USG
1997-05-12  4:00       ` Peter Kocourek
1997-05-09  4:00 ` Jonathan Rozes
     [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