* Re: horrible "cc -O" bug (DU 3.2c)
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
[not found] ` <5l7hap$7la@usenet.pa.dec.com>
2 siblings, 2 replies; 18+ messages in thread
From: John Hascall @ 1997-05-09 4:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* 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
* Re: horrible "cc -O" bug (DU 3.2c)
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
[not found] ` <5l7hap$7la@usenet.pa.dec.com>
2 siblings, 0 replies; 18+ messages in thread
From: Jonathan Rozes @ 1997-05-09 4:00 UTC (permalink / raw)
In article <E9wuF5.8JE@utcc.utoronto.ca>,
mark@cita.toronto.edu (Mark Bartelt) writes:
> 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!
>
> [...]
>
> We're running version 3.2c of Digital UNIX. Can anyone
> tell me whether this bug got fixed in 4.0?
On 3.2g, I got a segfault with -O and -O2, but not -O3. The cc -migrate
compiler worked fine at all optimization levels.
On 4.0b, cc and cc.alt work fine at all optimization levels.
jonathan
--
+++ Jonathan Rozes, Unix Systems Administrator, Tufts University
++ jrozes@tcs.tufts.edu, http://rozes.tcs.tufts.edu/
+ Remember, there's a difference between kneeling down and
bending over --FZ
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-09 4:00 ` John Hascall
@ 1997-05-10 4:00 ` Gerald Feldman
1997-05-11 4:00 ` Roy Smith
1 sibling, 0 replies; 18+ messages in thread
From: Gerald Feldman @ 1997-05-10 4:00 UTC (permalink / raw)
John Hascall wrote:
>
> 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...
Interesting. BTW: The cc command in V3.2c is the old MIPS based compiler
that has been retired. The cc -migrate is the newer DECC compiler. I am
not sure thnat this is really a bug. As long as the evaluation does not
cause any side effects. Remember that on the Alpha chip, 2 or 4
instaructions can be executed at the same time. (eg. dual or quad
issue). even with the branch code, the float instructions will have been
prefetched, and may be executed before the branch completes. The code is
only wrong if it were to cause a floating exception when flag is zero,
or if the cost of evaluating argument 2 is higher than the conditional
branch.
--
+----------------------------------------------+
| Jerry Feldman <gaf@highway1.com> |
| Boston Computer Solutions and Consulting |
| http://gaf.ne.highway1.com/ |
+----------------------------------------------+
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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 ` Gerald A. Feldman
1997-05-11 4:00 ` Michael C. Grant
1 sibling, 2 replies; 18+ messages in thread
From: Roy Smith @ 1997-05-11 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.
Any compiler code generation bug is "really disturbing". This has to be any
programmer's worst nightmare. The thought of doing any kind of software
developent on a compiler that isn't doing 100% rock-solid code generation
gives me the willies. I can live with slow code. I can live with missing
language features. I can live with parsers unable to handle arbitrarily
complex expressions. But if it compiles, I have to *know* it compiled
correctly.
We're running DU-4.0B on our new alpha boxes. Is this a problem in the
compiler that ships with that system? Should I be pointing my ftp
connection at MIT and downloading gcc if I want to be able to sleep nights?
--
Roy Smith <roy@popmail.med.nyu.edu>
New York University School of Medicine
Copyright 1997 Roy Smith
For-profit redistribution prohibited
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-11 4:00 ` Roy Smith
@ 1997-05-11 4:00 ` Gerald A. Feldman
1997-05-11 4:00 ` Roy Smith
` (3 more replies)
1997-05-11 4:00 ` Michael C. Grant
1 sibling, 4 replies; 18+ messages in thread
From: Gerald A. Feldman @ 1997-05-11 4:00 UTC (permalink / raw)
Roy Smith wrote: Any compiler code generation bug is "really
disturbing". This has to be any
> programmer's worst nightmare. The thought of doing any kind of
> software
> developent on a compiler that isn't doing 100% rock-solid code
> generation
> gives me the willies. I can live with slow code. I can live with
> missing
> language features. I can live with parsers unable to handle
> arbitrarily
> complex expressions. But if it compiles, I have to *know* it compiled
>
> correctly.
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. In this case, it works nicely because the alpha
chips can dual issue the code. In the 5 years I have been in the Unix
Development Environment group, I have not heard of a bug where the
second argument is evaluated before the first. You could say the same
thing about the way the Alpha compilers pass arguments to functions. The
first 6 arguments are passed as registers, not pushed on the stack.
> We're running DU-4.0B on our new alpha boxes. Is this a problem in
> the
> compiler that ships with that system? Should I be pointing my ftp
> connection at MIT and downloading gcc if I want to be able to sleep
> nights?
DU 4.0B ships with DECC as the default compiler and ACC as a backup. GCC
also ships with DU. I think you will find that code generated by gcc is
slower than code generated by DECC or ACC.BTW: The newer Alpha chips
quad issue instructions, which means that the chip can execute 4
instructions in parallel. All Digital compilers and assemblers schedule
the generated code for optimal execution. The instructions are
rearranged based on latencies and other interactions. The scheduler
knows the issue rules, and tries to schedule the instructions to take
advantage of this. This is over and above normal compiler optimizations.
Both ACC and DECC go through a large number of tests and soaks. Not only
their own suites, but they are tested in many different standards
validation suites, and are fully certified by the appropriate standards
bodies. Both are very stable in V3.2C as well as on 4.0B. If the bug
that was described actually is a bug, I doubt that even the kernel could
be built.
--
+----------------------------------------------+
| Jerry Feldman <gaf@highway1.com> |
| Boston Computer Solutions and Consulting |
| http://gaf.ne.highway1.com/ |
+----------------------------------------------+
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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 ` Mark Bartelt
1997-05-12 4:00 ` Jeff Sullivan USG
` (2 subsequent siblings)
3 siblings, 2 replies; 18+ messages in thread
From: Roy Smith @ 1997-05-11 4:00 UTC (permalink / raw)
"Gerald A. Feldman" <gaf@highway1.com> writes:
>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.
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.
The language semantics say that in "x && y", y is not evaluated unless x is
true. This lets you do things like "xp && *xp". Or "is_valid(foo) &&
get_value(foo)". Or "x < 3 && x++". Some of those may be ugly, but they
are legal, and all require that the part after the && not be evaluated if
the part before the && is false.
Maybe I just misunderstood what is going on, but if the compiler doesn't
guarantee that behavior, it's broken (and I can start having nightmares).
If the compiler does indeed guarantee it, then I guess I just misunderstood
the original post.
> The newer Alpha chips quad issue instructions, which means that the chip
> can execute 4 instructions in parallel. All Digital compilers and
> assemblers schedule the generated code for optimal execution. The
> instructions are rearranged based on latencies and other interactions. The
> scheduler knows the issue rules, and tries to schedule the instructions to
> take advantage of this.
Multiple instruction scheduling is a kind of black magic invented to give
the hardware guys nightmares. As long as they did their job right (i.e.
invested a sufficient number of sleepless nights sitting bolt upright in bed
at 3AM in a cold sweat), us software types can sleep nights knowing that the
language semantics are being obeyed, no matter how ugly it may get inside
that funny looking chip with the cooling fins.
--
Roy Smith <roy@popmail.med.nyu.edu>
New York University School of Medicine
Copyright 1997 Roy Smith
For-profit redistribution prohibited
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-11 4:00 ` Roy Smith
1997-05-11 4:00 ` Gerald A. Feldman
@ 1997-05-11 4:00 ` Michael C. Grant
1 sibling, 0 replies; 18+ messages in thread
From: Michael C. Grant @ 1997-05-11 4:00 UTC (permalink / raw)
>Any compiler code generation bug is "really disturbing". This has to be
any
>programmer's worst nightmare. The thought of doing any kind of software
>developent on a compiler that isn't doing 100% rock-solid code generation
>gives me the willies. I can live with slow code. I can live with
missing
>language features. I can live with parsers unable to handle arbitrarily
>complex expressions. But if it compiles, I have to *know* it compiled
>correctly.
Sorry, I don't buy this. If you're serious about QA, you put release
versions through their paces just like you put debug versions. People don't
do line-by-line proofs that their million-line programs are bug-free---they
do black-box testing. As such, bugs caused by compiler errors should be
treated the same way as bugs in your code.
Now that's not to say that you should ignore compiler quality, of
course---but an occasional compiler bug is part of the game.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-11 4:00 ` Roy Smith
1997-05-12 4:00 ` Jeff Sullivan USG
@ 1997-05-12 4:00 ` Mark Bartelt
1997-05-12 4:00 ` Andy Isaacson
1 sibling, 1 reply; 18+ messages in thread
From: Mark Bartelt @ 1997-05-12 4:00 UTC (permalink / raw)
[ 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.
[ 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.
As a parenthetical and somewhat off-topic aside, I'd leave *that* one for the
philosophers, as a code-generator analogue of "if a tree falls in a forest ..."
sort of question. I *have* encountered compilers which don't bother assigning
any value at all to a variable if they can determine with 100% certainty that
the variable is never used subsequent to the requested assignment.
However, to get back on-track ...
[ Roy Smith ]
>> The language semantics say that in "x && y", y is not evaluated unless x is
>> true. This lets you do things like "xp && *xp". Or "is_valid(foo) &&
>> get_value(foo)". Or "x < 3 && x++". Some of those may be ugly, but they
>> are legal, and all require that the part after the && not be evaluated if
>> the part before the && is false.
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.
Mark Bartelt 416/978-5619
Canadian Institute for mark@cita.utoronto.ca
Theoretical Astrophysics http://www.cita.utoronto.ca/~mark
"Sheep not busy being shorn are busy frying" -- Dylan, at a NZ lamb barbecue
[ singing "It's all right, ma (I'm only bleating)" ]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-12 4:00 ` Andy Isaacson
@ 1997-05-12 4:00 ` John Reinitz
1997-05-13 4:00 ` Mark Bartelt
1 sibling, 0 replies; 18+ messages in thread
From: John Reinitz @ 1997-05-12 4:00 UTC (permalink / raw)
In article <slrn5nejpr.d7o.adisaacs@supreme.csl.mtu.edu>,
Andy Isaacson <adisaacs@mtu.edu> wrote:
>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.)
>
Uh... isn't a core dump rather observable?
I would buy your argument if the instruction was executed
but did not trap.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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 ` Peter Kocourek
1997-05-12 4:00 ` Bob Vickers
3 siblings, 0 replies; 18+ messages in thread
From: Peter Kocourek @ 1997-05-12 4:00 UTC (permalink / raw)
Gerald A. Feldman <gaf@highway1.com> wrote:
> 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. In this case, it works nicely because the alpha
[snip]
The C standard explicitly forbids the execution of the rhs expression of
the && operator, if the lhs expression if false. Writing
x && 1/x
should never cause a divide-by-zero exception (or the equivalent an
Alpha's.)
If the DEC compiler does execute 1/x, even if x is zero, it's broken.
Peter.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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
1 sibling, 1 reply; 18+ messages in thread
From: Jeff Sullivan USG @ 1997-05-12 4:00 UTC (permalink / raw)
The problem reported is in fact a problem with the old "ACC" compiler
on Digital UNIX. It is not a problem with DEC C, which is the default
compiler on V4.0 and can be accessed via "cc -migrate" on V3.2. The
problem in ACC (-oldc) has been officially reported as a "showstopper"
and is expected to be fixed in a future release.
The test case has been added to the DEC C regression test suite to
ensure that this never becomes a problem in DEC C.
-Jeff
--
Jeff Sullivan | Digital Equipment Corp | sullivan@decc.enet.dec.com
DEC C and C++ | Nashua, NH ZK3-2/2X09 | or jps@zk3.dec.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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 ` Peter Kocourek
1997-05-12 4:00 ` Bob Vickers
3 siblings, 0 replies; 18+ messages in thread
From: Jeff Sullivan USG @ 1997-05-12 4:00 UTC (permalink / raw)
The problem reported is a real problem in the ACC (-oldc) compiler.
It is not a problem in DEC C, which is the default compiler for
Digital UNIX V4.0 (and can be invoked as "cc -migrate" on V3.2).
The problem was reported officially to the ACC group and we expect
that it will be resolved in a future release.
Thanks for reporting it.
-Jeff
--
Jeff Sullivan | Digital Equipment Corp | sullivan@decc.enet.dec.com
DEC C and C++ | Nashua, NH ZK3-2/2X09 | or jps@zk3.dec.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
[not found] ` <5l7hap$7la@usenet.pa.dec.com>
@ 1997-05-12 4:00 ` Gerald A. Feldman
0 siblings, 0 replies; 18+ messages in thread
From: Gerald A. Feldman @ 1997-05-12 4:00 UTC (permalink / raw)
Stephen Hoff Hoffman wrote:
> The default C compiler under UNIX V4.0 is DEC C, a completely
different
> compiler from the PCC compiler that is the default compiler on earlier
> UNIX versions.Unless this was a typo, the compiler prior to V4.0 is
referrred to as the ACC compiler. It has no relationship to AT&T's
Portable C Compiler (PCC). The ACC compiler did serve well. It was used
to port OSF1 as well as Windows NT to the Alpha, and still was able to
pass all the standards tests.
--
+----------------------------------------------+
| Jerry Feldman <gaf@highway1.com> |
| Boston Computer Solutions and Consulting |
| http://gaf.ne.highway1.com/ |
+----------------------------------------------+
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
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
0 siblings, 2 replies; 18+ messages in thread
From: Andy Isaacson @ 1997-05-12 4:00 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-12 4:00 ` Jeff Sullivan USG
@ 1997-05-12 4:00 ` Gerald A. Feldman
0 siblings, 0 replies; 18+ messages in thread
From: Gerald A. Feldman @ 1997-05-12 4:00 UTC (permalink / raw)
Jeff Sullivan USG wrote:
> The problem reported is in fact a problem with the old "ACC" compiler
> on Digital UNIX. It is not a problem with DEC C, which is the default
> compiler on V4.0 and can be accessed via "cc -migrate" on V3.2. The
> problem in ACC (-oldc) has been officially reported as a "showstopper"
>
> and is expected to be fixed in a future release.
>
> The test case has been added to the DEC C regression test suite to
> ensure that this never becomes a problem in DEC C.
>
I stand corrected on my post of yesterday. The example does cause a
side effect. I did file the "showstopper"myself after testing the test
case. As I mentioned, the default compiler for V3.2 releases is the ACC
compiler, which has been retired in favor of DECC in V4.0. DECC is
available with the -migrate switch in V3.2x.
--
+----------------------------------------------+
| Jerry Feldman <gaf@highway1.com> |
| Boston Computer Solutions and Consulting |
| http://gaf.ne.highway1.com/ |
+----------------------------------------------+
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-11 4:00 ` Gerald A. Feldman
` (2 preceding siblings ...)
1997-05-12 4:00 ` Peter Kocourek
@ 1997-05-12 4:00 ` Bob Vickers
3 siblings, 0 replies; 18+ messages in thread
From: Bob Vickers @ 1997-05-12 4:00 UTC (permalink / raw)
To: Gerald A. Feldman
Gerald A. Feldman wrote:
>
> Lots of stuff about instruction scheduling, multiple execution etc etc
>
This is all very interesting but completely irrelevant to the issue of
whether there is a compiler bug. If the program doesn't behave as the
standard says it should then it is a bug. It certainly looks like a bug
to me.
But Roy Smith's reaction is way over the top. A good working assumption
is that all compilers have bugs, but some have more than others.
Bob
--
======================================================================
Bob Vickers R.Vickers@rhbnc.ac.uk
Dept of Computer Science, Royal Holloway College, University of London
WWW: http://www.dcs.rhbnc.ac.uk/%7Ebobv/
Phone: +44 1784 443691
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: horrible "cc -O" bug (DU 3.2c)
1997-05-12 4:00 ` Andy Isaacson
1997-05-12 4:00 ` John Reinitz
@ 1997-05-13 4:00 ` Mark Bartelt
1 sibling, 0 replies; 18+ messages in thread
From: Mark Bartelt @ 1997-05-13 4:00 UTC (permalink / raw)
[ Andy Isaacson ]
>> Absolutely. However, the "bug" was observed by inspecting disassembled
>> object code. This is a case of the "looks like" effect.
Um, no. This bug (no quotes around it, since it *is* a bug) was discovered
because a correct program dumped core. I posted the original code fragment
which demonstrated the problem. Someone else posted the disassembled object
code, to show exactly *how* the compiler was screwing up.
>> 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.
Sorry, go back and read the thread in its entirety, from the beginning. That
should convince you that this really *is* a bug. (And a couple of Digits have
acknowledged, via e-mail, that they agree.)
Mark Bartelt 416/978-5619
Canadian Institute for mark@cita.utoronto.ca
Theoretical Astrophysics http://www.cita.utoronto.ca/~mark
"Sheep not busy being shorn are busy frying" -- Dylan, at a NZ lamb barbecue
[ singing "It's all right, ma (I'm only bleating)" ]
^ 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 ` 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 ` Jeff Sullivan USG
1997-05-12 4:00 ` Peter Kocourek
1997-05-12 4:00 ` Bob Vickers
1997-05-11 4:00 ` Michael C. Grant
[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