From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,ae6d7754224e7cfb,start X-Google-Attributes: gidfee84,public X-Google-Thread: 1164f8,ae6d7754224e7cfb,start X-Google-Attributes: gid1164f8,public From: john@iastate.edu (John Hascall) Subject: Re: horrible "cc -O" bug (DU 3.2c) Date: 1997/05/09 Message-ID: <5kvqsu$18d$1@news.iastate.edu>#1/1 X-Deja-AN: 240462653 References: Organization: Iowa State University, Ames, Iowa USA Newsgroups: comp.unix.osf.osf1,comp.sys.dec Mark Bartelt 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