From: Josh Cartwright <joshc@codeaurora.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/3] typecheck: introduce assign_if() and assign_if_enabled()
Date: Thu, 27 Feb 2014 17:48:50 -0600 [thread overview]
Message-ID: <20140227234850.GC7308@joshc.qualcomm.com> (raw)
In-Reply-To: <20140227190032.GA4421@kroah.com>
On Thu, Feb 27, 2014 at 11:00:32AM -0800, Greg Kroah-Hartman wrote:
> On Mon, Feb 24, 2014 at 11:08:25AM -0600, Josh Cartwright wrote:
> > +/*
> > + * Intended for use in static object initializers,
> > + * assign_if(const_expr, function) evaluates to 'function' if 'const_expr',
> > + * otherwise NULL.
> > + *
> > + * The type of the assign_if() expression is typeof(function), and therefore
> > + * can provide typechecking regardless of 'const_expr'.
> > + *
> > + * gcc considers 'function' to be used and will not generate a 'defined but not
> > + * used' warning when not 'const_expr', however, gcc is smart enough to
> > + * eliminate 'function' if assign_if() is the only reference.
> > + */
>
> What version of gcc started doing this? Does llvm also do this?
I'll need to dig up some old gcc's to give this a more thorough
testing; testing with clang 3.4, and it appears to have the same
behavior, at least when I throw a trivial usecase at it.
$ clang --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
$ cat test.c
static void foo(void)
{
extern void BROKEN(void);
BROKEN();
}
void (*callback)(void) = 0 ? foo : 0;
$ clang -Wall -Werror -c test.c
$ size test.o
text data bss dec hex filename
0 0 8 8 8 /tmp/test.o
$ nm test.o
0000000000000000 B callback
Although, given the feedback on the other patches, assign_if() may
become just be a solution in search of a problem :).
Thanks,
Josh
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
next prev parent reply other threads:[~2014-02-27 23:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-24 17:08 [PATCH 0/3] introduce assign_if() macros in attempt to reduce ifdeffery Josh Cartwright
2014-02-24 17:08 ` [PATCH 1/3] typecheck: introduce assign_if() and assign_if_enabled() Josh Cartwright
2014-02-27 19:00 ` Greg Kroah-Hartman
2014-02-27 23:48 ` Josh Cartwright [this message]
2014-02-24 17:08 ` [PATCH 2/3] PM: define new ASSIGN_*_PM_OPS macros based on assign_if Josh Cartwright
2014-02-27 19:02 ` Greg Kroah-Hartman
2014-03-01 11:06 ` Pavel Machek
2014-03-01 16:02 ` Greg Kroah-Hartman
2014-03-01 16:26 ` Pavel Machek
2014-02-24 17:08 ` [PATCH 3/3] usb: phy: msm: use ASSIGN_*_PM_OPS variants Josh Cartwright
[not found] ` <1393261707-30565-4-git-send-email-joshc-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-02-25 18:33 ` Felipe Balbi
2014-02-27 19:03 ` Greg Kroah-Hartman
2014-02-27 23:41 ` David Cohen
2014-02-27 23:44 ` Greg Kroah-Hartman
[not found] ` <20140227234425.GA32426-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2014-02-27 23:52 ` David Cohen
2014-02-28 8:48 ` Ulf Hansson
2014-02-28 16:52 ` Greg Kroah-Hartman
2014-03-01 11:24 ` Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140227234850.GC7308@joshc.qualcomm.com \
--to=joshc@codeaurora.org \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).