From: Michal Nazarewicz <mina86@mina86.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Mark Rustad <mark.d.rustad@intel.com>, "Kirsher\,
Jeffrey T" <jeffrey.t.kirsher@intel.com>,
"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Hagen Paul Pfeifer <hagen@jauu.net>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH 2/2] kernel.h: use __COUNTER__ in min and max macros to avoid -Wshadow warnings
Date: Sat, 13 Sep 2014 01:37:40 +0200 [thread overview]
Message-ID: <xa1tppf0xvej.fsf@mina86.com> (raw)
In-Reply-To: <20140912154013.47dad90e7519146c6da115e5@linux-foundation.org>
On Fri, Sep 12 2014, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Thu, 11 Sep 2014 23:39:36 +0200 Michal Nazarewicz <mina86@mina86.com> wrote:
>
>> Because min and max macros use the same variable names no matter
>> how many times they are called (or how deep the nesting of their
>> calls), each time min or max calls are nested, the same variables
>> are declared. This is especially noisy after min3 and max3 have
>> been changed to nest min/max calls.
>>
>> Using __COUNTER__ solves the problem since each variable will get
>> a unique number aadded to it. The code will still work even if
>> the compiler does not support __COUNTER__, but then the protection
>> from shadow warning won't work.
>>
>> The same applies to min_t and max_t macros.
>>
>> ...
>>
>> --- a/include/linux/kernel.h
>> +++ b/include/linux/kernel.h
>> @@ -695,15 +695,27 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
>> #endif /* CONFIG_TRACING */
>>
>> /*
>> + * Preprocessor magic generating unique identifiers to avoid -Wshadow warnings
>> + * used by min, max, min_t and max_t macros. cnt is __COUNTER__, op is the
>> + * comparison operator; tx (ty) is type of the first (second) argument,
>> + * xx (yy) is name of a temporary variable to hold the first (second) argument,
>> + * and x (y) is the first (second) argument.
>> + */
>> +#define _min_max_var(cnt, base) _mm_ ## cnt ## base
>> +#define _min_max__(op, tx, xx, x, ty, yy, y) ({ \
>> + tx xx = (x); \
>> + ty yy = (y); \
>> + (void) (&xx == &yy); \
>> + xx op yy ? xx : yy; })
>> +#define _min_max_(cnt, op, tx, x, ty, y) \
>> + _min_max__(op, tx, _min_max_var(cnt, a), x, ty, _min_max_var(cnt, b), y)
>> +#define _min_max(...) _min_max_(__COUNTER__, __VA_ARGS__)
>
> The fact that __COUNTER__ is used in compiler-gcc4.h but not in
> compiler-gcc3.h makes me suspicious about its availability?
http://gcc.gnu.org/ml/gcc-patches/2007-05/msg01579.html so looks like it
has 7 years. But as the commit message says, the code will still work,
even w/o working __COUNTER__.
> I do think that [1/2] made the code significantly worse-looking
Oh? I actually thought [1/2] makes it nicer by having a single place
where the min/max logic is implemented.
> and this one is getting crazy. How useful is W=2 anyway?
I actually do agree with that. I didn't have high hopes about getting
this patch accepted, but wanted to send it out to show that it can be
done, if it's really deemed useful.
> Has anyone found a bug using it? The number of warnings in default
> builds is already way too high :(
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
next prev parent reply other threads:[~2014-09-12 23:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1409837300.2460.10.camel@jtkirshe-mobl>
2014-09-04 21:38 ` kernel: Resolve a shadow warning Andrew Morton
2014-09-04 23:03 ` Rustad, Mark D
2014-09-11 21:39 ` [PATCH 1/2] include: kernel.h: deduplicate code implementing min*, max* and clamp* macros Michal Nazarewicz
2014-09-11 21:39 ` [PATCH 2/2] kernel.h: use __COUNTER__ in min and max macros to avoid -Wshadow warnings Michal Nazarewicz
2014-09-12 22:40 ` Andrew Morton
2014-09-12 23:37 ` Michal Nazarewicz [this message]
2014-09-12 23:48 ` Rustad, Mark D
2014-09-12 23:43 ` Rustad, Mark D
2014-09-13 0:12 ` Andrew Morton
2014-09-25 15:50 ` [PATCH] include: kernel.h: deduplicate code implementing clamp* macros Michal Nazarewicz
2014-09-25 19:46 ` Hagen Paul Pfeifer
2014-09-26 20:04 ` Michal Nazarewicz
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=xa1tppf0xvej.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=akpm@linux-foundation.org \
--cc=hagen@jauu.net \
--cc=jeffrey.t.kirsher@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.d.rustad@intel.com \
--cc=rostedt@goodmis.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
Powered by JetHome