From owner-freebsd-current@FreeBSD.ORG Sun Apr 10 17:49:42 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4A1CB16A4CF; Sun, 10 Apr 2005 17:49:42 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id B629D43D49; Sun, 10 Apr 2005 17:49:41 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.3/8.13.1) with ESMTP id j3AHncbR004938; Sun, 10 Apr 2005 13:49:38 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.3/8.13.1/Submit) id j3AHncA2004937; Sun, 10 Apr 2005 13:49:38 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Date: Sun, 10 Apr 2005 13:49:38 -0400 From: David Schultz To: Chuck Swiger Message-ID: <20050410174938.GA4842@VARK.MIT.EDU> Mail-Followup-To: Chuck Swiger , Daniel Ellard , freebsd-fs@FreeBSD.ORG, freebsd-current@FreeBSD.ORG References: <200504100251.j3A2pLEH055107@sana.init-main.com> <20050410074009.N66651@bowser.eecs.harvard.edu> <1892195662.20050410140423@andric.com> <20050410082945.H66651@bowser.eecs.harvard.edu> <42595E04.60705@mac.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42595E04.60705@mac.com> cc: freebsd-fs@FreeBSD.ORG cc: Daniel Ellard cc: freebsd-current@FreeBSD.ORG Subject: Re: smbfs bug introduced at smbfs_vnops.c:1.58 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Apr 2005 17:49:42 -0000 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...