Date: Sun, 10 Apr 2005 08:44:44 -0400 (EDT) From: Daniel Ellard <ellard@eecs.harvard.edu> To: Dimitry Andric <dimitry@andric.com> Cc: freebsd-current@freebsd.org Subject: Re: smbfs bug introduced at smbfs_vnops.c:1.58 Message-ID: <20050410082945.H66651@bowser.eecs.harvard.edu> In-Reply-To: <1892195662.20050410140423@andric.com> References: <200504100251.j3A2pLEH055107@sana.init-main.com> <20050410074009.N66651@bowser.eecs.harvard.edu> <1892195662.20050410140423@andric.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 10 Apr 2005, Dimitry Andric wrote:
> > If you change the -O to -g, then the code for "a" is not
> > removed -- but there's still no warning. I think this is
> > a bug, because if the expression wasn't an innocuous a+=1
> > it could be a real problem if the variable wasn't removed.
>
> The idea here is that gcc sees that the value of a is never used, and
> therefore it doesn't have to warn. (Whether you agree with this, or
> not, is more of a political or philosophical question. ;) But as soon
> as you actually *do* something with a's value afterwards, it will
> start to complain.
Well, I guess have to give an example...
int main(void) {
int a;
int b[1];
a = b[a * 10000]; /* Uses the value of a. */
return (0);
}
If you compile this with -O, then the "a = " line is
optimized away, and the deref of some random piece
of memory goes away.
If you compile this without the -O then now you
have a deref to something whose address depends
on an uninitialized variable. Sorry, that's bad.
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...)
My philosophy is that the compiler should warn
you about things in the un-optimized, un-transformed
code (because that's where I put my bugs -- if I've
written code that has no effect, that's probably not
what I meant). I'd rather get extraneous warnings
than miss something. Of course, everyone is welcome
to their own philosophy. (But how politics enter
into this, I don't want to know.)
-Dan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050410082945.H66651>
