Re: smbfs bug introduced at smbfs_vnops.c:1.58

From: Erik Trulsson <ertr1013_at_student.uu.se>
Date: Sun, 10 Apr 2005 20:04:50 +0200
On Sun, Apr 10, 2005 at 01:10:28PM -0400, Chuck Swiger wrote:
> Daniel Ellard wrote:
> >On Sun, 10 Apr 2005, Dimitry Andric wrote:
> [ ... ]
> >At least the gcc folk now do detect this old chestnut:
> >
> >	{
> >	    int a;
> >
> >	    a /= 0;
> >	}
> >
> >which was used to provoke arguments in compiler
> >classes for many years.  (Optimized, nothing happens.
> >Unoptimized, a division-by-zero error happens...)
> 
> Great example.
> 
> If the optimized code fails to generate a division-by-zero error here, the 
> optimizer is buggy.

Not at all.  Division by zero means undefined behaviour (at least in
C.) Undefined behaviour means *anything* may happen - including no
error happening. A compiler optimizing away the division-by-zero is
perfectly correct in doing so. (It is also perfectly correct to not
optimize away the error.)

>  (I won't quote Aho, Sethi, and Ullman again.... :-)

No, please don't - especially since that quote you are so fond of isn't
*quite* correct - an optimizer is allowed to change the output of a
program as long as the new output is also correct according to the
language specification.  (Language specifications often do not specify
every detail, with the result that for a given program it can be the
case that more than one output can be correct.  In C any instance of
undefined behaviour in a program means that *no* aspect of the program
is defined and therefore all different outputs will be equally
correct.)

-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013_at_student.uu.se
Received on Sun Apr 10 2005 - 16:04:55 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:31 UTC