From owner-freebsd-arch@FreeBSD.ORG Sat Mar 7 19:16:50 2009 Return-Path: Delivered-To: arch@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65941106566B for ; Sat, 7 Mar 2009 19:16:50 +0000 (UTC) (envelope-from das@FreeBSD.ORG) Received: from zim.MIT.EDU (ZIM.MIT.EDU [18.95.3.101]) by mx1.freebsd.org (Postfix) with ESMTP id 1E1288FC13 for ; Sat, 7 Mar 2009 19:16:50 +0000 (UTC) (envelope-from das@FreeBSD.ORG) Received: from zim.MIT.EDU (localhost [127.0.0.1]) by zim.MIT.EDU (8.14.3/8.14.2) with ESMTP id n27JL098036308; Sat, 7 Mar 2009 14:21:00 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by zim.MIT.EDU (8.14.3/8.14.2/Submit) id n27JL05T036307; Sat, 7 Mar 2009 14:21:00 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Sat, 7 Mar 2009 14:21:00 -0500 From: David Schultz To: Luigi Rizzo Message-ID: <20090307192100.GA36158@zim.MIT.EDU> Mail-Followup-To: Luigi Rizzo , arch@FreeBSD.ORG References: <20090307103138.GA34456@zim.MIT.EDU> <20090307112449.GB45088@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090307112449.GB45088@onelab2.iet.unipi.it> Cc: arch@FreeBSD.ORG Subject: Re: C99 inlines X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Mar 2009 19:16:50 -0000 On Sat, Mar 07, 2009, Luigi Rizzo wrote: > On Sat, Mar 07, 2009 at 05:31:38AM -0500, David Schultz wrote: > > I'd like the gcc in our tree to use the C99 semantics instead of GNU > > semantics for inline functions in C99 and GNU99 mode. The following > > patch implements this behavior. It is based on a snapshot of the gcc > > 4.3 branch from March 2007, prior to the GPLv3 switch. > > > > http://www.freebsd.org/~das/c99inline.diff > ... > > What do people think about this? > > would you be able to provide a short summary of how the C99 and > GNU99 semantics differ, so that people will have a easier time > figuring out how to handle the change ? > > Especially, is there anything that a developer should worry about, > or except from some corner cases the switch will (and should) be > completely transparent to the average developer without a specific > interest in compilers ? > > I know what I am asking is probably in the diff you supplied, > but it's a bit difficult to follow there Good point; it isn't clear at all from the diffs. Basically it all has to do with the interpretation of `inline' versus `extern inline'. Historical gcc semantics are incompatible with C99, but this was fixed in gcc 4.3. This patch essentially backports that patch from a development snapshot of gcc 4.3 prior to the GPLv3 switch. This page summarizes the differences pretty well, but ignore the last section: http://www.greenend.org.uk/rjk/2003/03/inline.html The most important point for developers is that the one kind of inline where gcc and C99 agree is `static inline', so if you use that, you won't have to worry. Otherwise, the semantics you get depend on many things: - gcc prior to 4.1.3: You always get GNU inline rules. - gcc 4.1.3 to 4.2.1 (the one in the tree): In -std=gnu89 mode, you get GNU inline rules. In -std=gnu99 or -std=c99 mode, you get a warning that GNU inline rules aren't implemented. - gcc 4.3+ or gcc with this patch: In -std=gnu89 mode, you get GNU inline rules. In -std=gnu99 or -std=c99 mode, you get C99 rules. You can use __gnu89_inline (defined in sys/cdefs.h) or -fgnu-inline to force the GNU rules regardless, but you can't get the C99 rules with an unpatched pre-4.3 compiler. In gcc 4.2+, the macros __GNUC_{GNU,STDC}_INLINE__ tell you what you're getting. With this patch, you basically get the semantics you asked for instead of a warning that they're not implemented. If you weren't getting warnings with gcc 4.2 before, then nothing changes. Another minor consequence of this patch is that it enables a few new warnings and errors involving non-static inlines. For instance, if you have an extern inline function that references a static variable, such that the function might refer to a *different* version of the variable depending on whether it's inlined or not, gcc will now tell you you're trying to do something bogus. It will also complain if you declare a function inline but never define it.