From owner-freebsd-fs@FreeBSD.ORG Sun Apr 10 12:44:45 2005 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7155B16A4CE; Sun, 10 Apr 2005 12:44:45 +0000 (GMT) Received: from mail.eecs.harvard.edu (bowser.eecs.harvard.edu [140.247.60.24]) by mx1.FreeBSD.org (Postfix) with ESMTP id D664743D54; Sun, 10 Apr 2005 12:44:44 +0000 (GMT) (envelope-from ellard@eecs.harvard.edu) Received: from localhost (localhost.eecs.harvard.edu [127.0.0.1]) by mail.eecs.harvard.edu (Postfix) with ESMTP id 59EB654C9FB; Sun, 10 Apr 2005 08:44:44 -0400 (EDT) Received: from mail.eecs.harvard.edu ([127.0.0.1]) by localhost (bowser.eecs.harvard.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 77977-09; Sun, 10 Apr 2005 08:44:44 -0400 (EDT) Received: by mail.eecs.harvard.edu (Postfix, from userid 465) id 17DE054C9A0; Sun, 10 Apr 2005 08:44:44 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.eecs.harvard.edu (Postfix) with ESMTP id 14E5154C993; Sun, 10 Apr 2005 08:44:44 -0400 (EDT) Date: Sun, 10 Apr 2005 08:44:44 -0400 (EDT) From: Daniel Ellard To: Dimitry Andric In-Reply-To: <1892195662.20050410140423@andric.com> Message-ID: <20050410082945.H66651@bowser.eecs.harvard.edu> References: <200504100251.j3A2pLEH055107@sana.init-main.com> <20050410074009.N66651@bowser.eecs.harvard.edu> <1892195662.20050410140423@andric.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at eecs.harvard.edu cc: freebsd-fs@freebsd.org cc: bp@freebsd.org cc: Ulrich Spoerlein cc: freebsd-current@freebsd.org Subject: Re: smbfs bug introduced at smbfs_vnops.c:1.58 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Apr 2005 12:44:45 -0000 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