Date: Thu, 18 Mar 2004 08:48:58 -0800 (PST) From: John Polstra <jdp@polstra.com> To: (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=) <des@des.no> Cc: net@freebsd.org Subject: Re: libalias patch for review / testing Message-ID: <XFMail.20040318084858.jdp@polstra.com> In-Reply-To: <xzpllm0ie5z.fsf@dwp.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On 16-Mar-2004 Dag-Erling Smørgrav wrote: > Ruslan Ermilov <ru@FreeBSD.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20040318084858.jdp>