Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932219AbVIRVxD (ORCPT ); Sun, 18 Sep 2005 17:53:03 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932220AbVIRVxD (ORCPT ); Sun, 18 Sep 2005 17:53:03 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:48004 "EHLO ZenIV.linux.org.uk") by vger.kernel.org with ESMTP id S932219AbVIRVxB (ORCPT ); Sun, 18 Sep 2005 17:53:01 -0400 Date: Sun, 18 Sep 2005 22:52:57 +0100 From: Al Viro To: Roman Zippel Cc: Linus Torvalds , Willy Tarreau , Robert Love , Russell King , Linux Kernel List Subject: Re: p = kmalloc(sizeof(*p), ) Message-ID: <20050918215257.GA29417@ftp.linux.org.uk> References: <20050918100627.GA16007@flint.arm.linux.org.uk> <1127061146.6939.6.camel@phantasy> <20050918165219.GA595@alpha.home.local> <20050918171845.GL19626@ftp.linux.org.uk> <20050918174549.GN19626@ftp.linux.org.uk> <20050918211225.GP19626@ftp.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050918211225.GP19626@ftp.linux.org.uk> User-Agent: Mutt/1.4.1i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1310 Lines: 35 On Sun, Sep 18, 2005 at 10:12:25PM +0100, Al Viro wrote: > Compound literal _is_ an object, all right. However, decision to allocate > storage for given object is up to compiler and it's hardly something unusual. > "Value of right-hand side is not needed to finish calculating left-hand side, > so its storage is fair game from that point on" is absolutely normal. BTW, for some idea of how hard does it actually blow, with struct foo { int a, b[100]; }; we get void f(struct foo *p) { *p = (struct foo){.b[1] = 2}; } compiled essentially to void f(struct foo *p) { static struct foo hidden_const = {.b[1] = 2}; auto struct foo hidden_var; memcpy(&hidden_var, &hidden_const, sizeof(struct foo)); memcpy(p, &hidden_var, sizeof(struct foo)); } That's right - two memcpy back-to-back, both inserted by gcc, intermediate object lost immediately after the second one, both source and intermediate introduced by gcc, so it knows that there is no aliasing problems to be dealt with. And yes, that's with optimizations turned on - -O2 and -Os generate the same. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/