Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: adisaacs@mtu.edu (Andy Isaacson)
Subject: Re: horrible "cc -O" bug (DU 3.2c)
Date: 1997/05/12	[thread overview]
Message-ID: <slrn5nejpr.d7o.adisaacs@supreme.csl.mtu.edu> (raw)
In-Reply-To: EA2EBs.Fo2@utcc.utoronto.ca


The USENET cabal made Mark Bartelt <mark@cita.toronto.edu> say:
>[ Gerald A. Feldman ]
>
>>>  First of all, from looking at the code, it does not appear to be a code
>>>  generation bug at all. It is only a bug if the code beyond the && would
>>>  cause a side effect, such as invoke a function, modify a variable, or
>>>  cause an exception.

exactly correct, in my opinion.  The compiler can do anything it wants, as
long as the result "looks like" the correct result from the program's
perspective.  (Of course, this could make debugging hard, but that's a
"quality of implementation" issue.)  If the code the compiler generates
ends up generating the correct results, why should I care how it gets
there?  (By correct results, I include _everything_ observable about the
program.)

>[ Roy Smith ]
>
>>>  That's like saying that if the code generated for "x = 3" actually assigns
>>>  the value 4 to x, it's only a bug if the value of x is used later in the
>>>  program.

It's only a bug if your program can be affected by it.  If you don't use the
value of x anywhere, what does it matter what value x has?  (Leaving the
issue of debugging aside for the moment.)

>Roy is spot-on correct on this point.  (Hey, I *have* to agree; I'm the one who
>started this whole thread! ;-)  When in doubt, consult scripture:  K&R makes it
>totally clear, when it says
>
>	Expressions connected by && or || are evaluated left to right,
>	and it is guaranteed that evaluation will stop as soon as the
>	truth or falsehood is known.
>
>QED.  Bug.  Case closed.

Absolutely.  However, the "bug" was observed by inspecting disassembled
object code.  This is a case of the "looks like" effect.  If the code to
the right of the || or && has no side effects, then the program
_cannot know_ if the code was executed or not.  In that case, the compiler
is completely justified in executing the code anyway, if it wants to.  If
the code has some side effects, however, the compiler must ensure that it
is not executed in error.

End result?  I am not convinced that this is a bug.  If the compiler
generates correct results for all cases, then it is not a bug.

just my .02 pence,
-andy
-- 
Andy Isaacson <adisaacs@mtu.edu> -- conserve bandwidth, use one line sigs.



  reply	other threads:[~1997-05-12  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
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 [this message]
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
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