Re: smbfs bug introduced at smbfs_vnops.c:1.58

From: David Schultz <das_at_FreeBSD.ORG>
Date: Sun, 10 Apr 2005 13:49:38 -0400
On Sun, Apr 10, 2005, 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.  (I won't quote Aho, Sethi, and Ullman again.... :-)

gcc's optimizer is notoriously bad with side-effects like this,
particularly for floating-point code.  The C99 standard requires
that the compiler support the FENV_ACCESS pragma to tell the
compiler that (among other things) it must not optimize away
arithmetic that may generate an exception as a side-effect, but
gcc doesn't implement it.  Worse yet, gcc defaults to assuming
that it *is* allowed to optimize such arithmetic operations away,
even in expressions such as '1.0 / 0.0' where it's clear what the
programmer wanted to happen.  A number of routines in libm don't
work properly at -O2 as a result of this, and in several places we
play tricks such as declaring variables to be volatile or 'long
double' just to trick the optimizer.  IIRC, Steve Moshier wrote
some gcc patches to fix this, but nobody ever committed them...
Received on Sun Apr 10 2005 - 15:49:42 UTC

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