From owner-freebsd-net@FreeBSD.ORG Thu Mar 18 08:49:03 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4179216A4CE; Thu, 18 Mar 2004 08:49:03 -0800 (PST) Received: from blake.polstra.com (blake.polstra.com [64.81.189.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id D5CD343D3F; Thu, 18 Mar 2004 08:49:02 -0800 (PST) (envelope-from jdp@polstra.com) Received: from strings.polstra.com (dsl081-189-067.sea1.dsl.speakeasy.net [64.81.189.67]) by blake.polstra.com (8.12.11/8.12.11) with ESMTP id i2IGmx3r050446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Mar 2004 08:48:59 -0800 (PST) (envelope-from jdp@strings.polstra.com) Received: (from jdp@localhost) by strings.polstra.com (8.12.11/8.12.11/Submit) id i2IGmwii029274; Thu, 18 Mar 2004 08:48:58 -0800 (PST) (envelope-from jdp) Message-ID: X-Mailer: XFMail 1.5.5 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Thu, 18 Mar 2004 08:48:58 -0800 (PST) From: John Polstra To: (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=) X-Bogosity: No, tests=bogofilter, spamicity=0.353069, version=0.14.5 cc: current@freebsd.org cc: net@freebsd.org Subject: Re: libalias patch for review / testing X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2004 16:49:03 -0000 On 16-Mar-2004 Dag-Erling Smørgrav wrote: > Ruslan Ermilov writes: >> I know this code quite well. Where do you suspect could be a bug >> affecting -O2 compiles, or you just simply fixed -O2 and hope it >> will auto-fix the (possible) bugs in -O2? > > Since there is no inline asm, the most likely suspect is aliasing, > which is what my patch tries to address. To eliminate aliasing problems reliably, I think you're going to have to use a union. That's the only kind of type punning that gcc promises to allow even at high optimization levels. From the info pages (in the description of "-fstrict-aliasing"): Pay special attention to code like this: union a_union { int i; double d; }; int f() { a_union t; t.d = 3.0; return t.i; } The practice of reading from a different union member than the one most recently written to (called "type-punning") is common. Even with `-fstrict-aliasing', type-punning is allowed, provided the memory is accessed through the union type. So, the code above will work as expected. However, this code might not: int f() { a_union t; int* ip; t.d = 3.0; ip = &t.i; return *ip; } Even if you use a union, it won't necessarily work with compilers other than gcc. John